Hi i need to write a XML schema for the validation of the document notes.xml. Wr
ID: 3556180 • Letter: H
Question
Hi i need to write a XML schema for the validation of the document notes.xml. Write the schema according to the following three approaches;
1.- Based on the document structure
2.- Structured (bottom-up design)
3.- Type-based (top-down design)
Here is the note.xml code, i will need the .xsd schema codes
<?xml version="1.0" encoding="ISO-8859-1"?>
<notes>
<note>
<date format="USA">
<month> 04</month>
<day>11</day>
<year>2014</year>
</date>
<time>
<hour> 23</hour>
<minute>11</minute>
<second>35</second>
</time>
<to id="101A" >Tove</to>
<to id="314F">Joe</to>
<from>Janie</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<date format="USA">
<month> 04</month>
<day>11</day>
<year>2014</year>
</date>
<to id="102F" >Anthony</to>
<from>Mary</from>
<heading>Reminder</heading>
<body>Please, bring me the textbook!</body>
</note>
</notes>
Explanation / Answer
Please find below .xsd
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="notes">
<xs:complexType>
<xs:sequence>
<xs:element name="note" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="date">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="month"/>
<xs:element type="xs:byte" name="day"/>
<xs:element type="xs:short" name="year"/>
</xs:sequence>
<xs:attribute type="xs:string" name="format" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="time" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="hour"/>
<xs:element type="xs:byte" name="minute"/>
<xs:element type="xs:byte" name="second"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="to" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="id" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="from"/>
<xs:element type="xs:string" name="heading"/>
<xs:element type="xs:string" name="body"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.