<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<note date="2015-09-01">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
<xs:attribute name="date" type="xs:date" use="required">
</xs:complexType>
</xs:element>
</xs:schema>
<note>
<date>2015-09-01</date>
<to>Tove</to>
<to>Wally</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="date" type="xs:date"/>
<xs:element name="to" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<note>
<date>
<day>23</day>
<month>September</month>
<year>2016</year>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="date" type="nestedDate" />
<xs:element name="to" type="xs:string" maxOccurs="unbounded" />
<xs:element name="from" type="xs:string" />
<xs:element name="heading" type="xs:string" />
<xs:element name="body" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="nestedDate">
<xs:sequence>
<xs:element name="year" type="xs:integer" />
<xs:element name="month" type="xs:string" />
<xs:element name="day" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="utf-8" ?>
<note>
<date>
<year>2016</year>
<month>January</month>
<day>2</day>
</date>
<to>Tove</to>
<to>Wally</to>
<from>Jani</from>
<heading>Reminder</heading>
<body language="english">Don't forget to feed the goats.</body>
</note>
####note.xsd - Final Schema
Includes:
- A custom complex type for the nested date date.
- Date month restricted using regular expression pattern to English month names or their abbreviations.
- Date day restricted to integers from 1 to 31.
- Allowance for multiple "to" elements.
- Body element is optional.
- A language attribute for the body element (by way of a custom type extending a simple type.)
Here it is:
<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note" type="emailNote" />
<xs:complexType name="emailNote" >
<xs:sequence>
<xs:element name="date" type="nestedDate"/>
<xs:element name="to" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="internationalizedString" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="nestedDate">
<xs:sequence>
<xs:element name="year" type="xs:integer"/>
<xs:element name="month" type="englishMonth"/>
<xs:element name="day" type="dayOfMonth"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="englishMonth">
<xs:restriction base="xs:string">
<xs:pattern value="Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sept(ember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="dayOfMonth">
<xs:restriction base="xs:positiveInteger">
<xs:maxInclusive value="31" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="internationalizedString">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>