Tutorial 03 Working with Schemas 1
Contents The University Hospital Problem Solution 2
The University Hospital Problem o The University Hospital stores information about its patients. Patient’s information must be store in a consistent format. Restrictions must be placed on the kind of data that can be saved in the data store to ensure uniformity and consistency of information. o The patient information comprise the name (first and last) of patient, date of Birth, age, stage, comments (optional, multiple) and his/her performance. o Every patient is uniquely identified by a patient ID, and the ID of the study in which the patient is enrolled. 3
Solution 1.Analysis and Design 2.Implementation 3.Testing 4
1. Analysis and Design Structure of the patients vocabulary: 5
1. Analysis and Design (cont.) ElementContent / Data Type PatientsComplex PatientComplex Last nameSimple / String First NameSimple / String Date of BirthSimple / String AgeSimple / Positive Number StageSimple / String CommentSimple / String PerformanceComplex / String 6 AttributeContent / Data Type patIDSimple / String onStudySimple / String scaleSimple / String
2. Implementation 2.1 Declaring Elements 2.2 Storing Elements 7
2.1 Declaring Elements Creating a new XML Schema file Inserting the root element Inserting the parent element Inserting the child elements Inserting the attribute 8
2.1.1 Creating a new XML Schema file Open XML Spy > File > New > xsd > OK Save the file as patients.xsd 9
2.1.2 Inserting the root element 10
2.1.3 Inserting the parent element 11
2.1.4 Inserting the child elements 12
2.1.5 Inserting the attribute 13
2.2 Storing Elements Creating a new XML document Applying the XML Schema into the XML document Inserting data 14
2.2.1 Creating a new XML document Create a new XML file and save it as patients.xml 15
2.2.2 Applying the XML Schema into the XML document 16
2.2.3 Inserting data Insert the patient information below (using the text file on Moodle) 17
3. Testing 3.1 Valid Case 3.2 Invalid Case 18
3.1 Valid Case 19
3.2 Invalid Case Suppose you delete one row in patient information, what will you see? 20
Extension 1.Each patient in document has a unique medical reference number that identifies the patient to the investigator. You decide to apply the ID data type to values of this attribute. To apply the ID data type: Change the type value from “xs:string” to “xs:ID” 2.You have recorded the date of birth of each patient in XML document. To apply the date data type: change the data type to xs:date 21
Extension 3.Every patient has to have the stage element containing either “I” for Stage I cancer patients or “II” for Stage II. To create the stageType data type: change the base type in the stage element from “xs:string” to “stageType” 22
Extension 4.Patients must be at least 21 years of age in order to give informed consent. To create the ageType data type: change the base type in the age element from “xs:positiveInterger” to “ageType”. 23
Extension 5.The performance scale varies from 0 to 1. To apply this decimal data types: change the base type in the performance element from “xs:string” to “perfType” 24
Exercise o The head office of Cyber Shop sends the information about its products to the branch offices. o The products details must be store in a consistent format at all branches. o Restrictions must be placed on the kind of data that can be saved in the data store to ensure uniformity and consistency of information. o The product details comprise the name of the product, a brief description about it, the price of the product, and the quantity available in stock, the price of the product must always be greater than zero. o Every product is uniquely indentified by a product ID. Create a XML Schema for the above case, reuse the XML document in the previous session to view data. 25
References New Perspectives on Creating Web Pages with HTML and XML (Patrick Carey & Mary Kemper) - Course Technology Publisher Creating Cool Web Sites with HTML, XHTML and CSS - Taylor, Dave, Wiley 26
27