
The purpose of a Schema is to define the legal building blocks of an XML document, just like a DTD.
BUT....
XML Schemas will be used in Web applications as a replacement for DTDs. Here are the reasons why:
Sample files:
We will be working with a number of sample files. You should open shippingOrder_xsd.xml and shippingOrder.xsd . If you have problems viewing the shippingOrder.xsd document, try opening shippingOrder.xml, which is the schema, shippingOrder.xsd, but has xml as the filetype so that you can view it directly in the browser. These are valid XML files, so IE 5.5 should be able to render them. A file which contains a reference to these schema (without data) is shipOrder.xml. The following is shippingOrder_xsd.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shippingOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shippingOrder.xsd">
<shipTo>
<name>Tove Svendson</name>
<street>Ragnhildvei 2</street>
<address>4000 Stavanger</address>
<country>Norway</country>
</shipTo>
<items>
<item>
<title>Empire Burlesque</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shippingOrder>
The following is the schema, shippingOrder.xsd.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="shippingOrder" type="shippingOrderType"/>
<xsd:complexType name="shippingOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="shipToType"/>
<xsd:element name="items" type="itemsType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="shipToType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="itemsType">
<xsd:sequence>
<xsd:element name="item" type="itemType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="itemType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:positiveInteger"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
We will be creating a schema document for our address book, address_book.xml shown in address_schema.xml and address_schema.xsd. These can serve as a working reference for your eventual project files.
<?xml version="1.0" encoding="UTF-8"?>
<shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shippingOrder.xsd">
<shipTo>
<name/>
<street/>
<address/>
<country/>
</shipTo>
<items>
<item>
<title/>
<quantity/>
<price/>
</item>
<item>
<title/>
<quantity/>
<price/>
</item>
</items>
</shipOrder>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation>This schema will be used for our address_book.xml document
</xsd:documentation>
</xsd:annotation>
<xsd:element name="address_book" type="addressBookType"/>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation>This schema will be used for our address_book.xml document
</xsd:documentation>
</xsd:annotation>
<xsd:element name="address_book" type="addressBookType"/>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--
The element name "address_book speaks to the root element of the XML document"
The type "addressBookType" will be defined as a complex element in the next part
-->
<xsd:element name="address_book" type="addressBookType"/>
</xsd:schema>
<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- The type "addressBookType" will be defined as a complexType --> <xsd:element name="address_book" type="addressBookType"/>
<!-- addressBookType contains the element "record" which isunbounded in occurance --> <xsd:complexType name="addressBookType"> <xsd:sequence> <xsd:element name="record" type="recordType" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the element sibling, which contains an anonymous element --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="siblings"> <xsd:complexType> <xsd:sequence> <xsd:element name="sibling" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The type "addressBookType" will be defined as a complexType -->
<xsd:element name="address_book" type="addressBookType"/>
<!-- addressBookType contains the element "record" which is unbounded in occurance -->
<xsd:complexType name="addressBookType">
<xsd:sequence>
<xsd:element name="record" type="recordType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- recordType contains the elements "name", "address", and "contact" -->
<!-- we use xsd:sequence to declare the order in which they will appear -->
<xsd:complexType name="recordType">
<xsd:sequence>
<xsd:element name="name" type="nameType"/>
<xsd:element name="address" type="addressType"/>
<xsd:element name="contact" type="contactType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The type "addressBookType" will be defined as a complexType -->
<xsd:element name="address_book" type="addressBookType"/>
<!-- addressBookType contains the element "record" which is unbounded in occurance -->
<xsd:complexType name="addressBookType">
<xsd:sequence>
<xsd:element name="record" type="recordType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- recordType contains the elements "name", "address", and "contact" -->
<!-- we use xsd:sequence to declare the order in which they will appear -->
<xsd:complexType name="recordType">
<xsd:sequence>
<xsd:element name="name" type="nameType"/>
<xsd:element name="address" type="addressType"/>
<xsd:element name="contact" type="contactType"/>
</xsd:sequence>
</xsd:complexType>
<!-- nameType conatins the elements "first_name", "middle_name", "last_name",
and "nick_name" -->
<!-- each of these elements is type "xsd:string" -->
<xsd:complexType name="nameType">
<xsd:sequence>
<xsd:element name="first_name" type="xsd:string"/>
<xsd:element name="middle_name" type="xsd:string"/>
<xsd:element name="last_name" type="xsd:string"/>
<xsd:element name="nick_name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- addressType conatins the elements "street_address", "street_address_detail",
"city", "state", and "zipcode" -->
<!-- each of these elements is type "xsd:string" -->
<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element name="street_address" type="xsd:string"/>
<xsd:element name="street_address_detail" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zipcode" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- complexType conatins the elements "home_phone", "work_phone", "cell_phone",
"fax_number", and "email_address" -->
<!-- each of these elements is type "xsd:string" -->
<xsd:complexType name="contactType">
<xsd:sequence>
<xsd:element name="home_phone" type="xsd:string"/>
<xsd:element name="work_phone" type="xsd:string"/>
<xsd:element name="cell_phone" type="xsd:string"/>
<xsd:element name="fax_number" type="xsd:string"/>
<xsd:element name="email_address" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0"?>
<!-- This is a short little zipcode document that relates to zipcode_schema.xml -->
<zipcodeType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="zipcode.xsd">
<zipcode>94020-0007</zipcode>
</zipcodeType>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="zipcodeType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="zipcode" type="zipcodeType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="zipcodeType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{5}(-\d{4})?"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0"?>
<accounting xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="accounting_schema.xsd">
<accounts>
<savings>100.01</savings>
<checking>250.99</checking>
<money_market>500.59</money_market>
</accounts>
</accounting>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="accounting" type="accountingType"/>
<xsd:element name="accounts" type="accountsType"/>
<xsd:element name="checking" type="accountFormat"/>
<xsd:element name="money_market" type="accountFormat"/>
<xsd:element name="savings" type="accountFormat"/>
<!-- ====================================================================== -->
<!-- Globally defined types -->
<!-- ====================================================================== -->
<xsd:complexType name="accountingType">
<xsd:sequence>
<xsd:element ref="accounts" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="accountsType">
<xsd:sequence>
<xsd:element ref="savings"/>
<xsd:element ref="checking"/>
<xsd:element ref="money_market"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="accountFormat">
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="10"/>
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0"?>
<!-- this document will show personal data related to dates -->
<!-- this document relates to the personal_schema.xml document -->
<personal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="personal.xsd">
<birthdate>1956-03-20</birthdate>
<year_born>1956</year_born>
<month_born>1956-03</month_born>
<instant_born>1956-03-20T15:27:46.2398Z</instant_born>
<birthday>--03-20</birthday>
</personal>
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="personal">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="birthdate"/>
<xsd:element ref="year_born"/>
<xsd:element ref="month_born"/>
<xsd:element ref="instant_born"/>
<xsd:element ref="birthday"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="birthdate" type="xsd:date"/>
<xsd:element name="birthday" type="xsd:string"/>
<xsd:element name="instant_born" type="xsd:dateTime"/>
<xsd:element name="month_born" type="xsd:string"/>
<xsd:element name="year_born" type="xsd:short"/>
</xsd:schema>
<?xml version="1.0"?>
<!-- this document will be used to show enumeration values -->
<!-- the schema for this document can be seen in astrological_schema.xml -->
<astrologicalType>
<astrological>Pisces</astrological>
</astrologicalType>
<?xml version="1.0"?>
<!-- This is the astrology schema that relates to astrological.xml -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="astrologicalType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="astrological" type="astrologicalType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="astrologicalType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Aries"/>
<xsd:enumeration value="Taurus"/>
<xsd:enumeration value="Gemini"/>
<xsd:enumeration value="Cancer"/>
<xsd:enumeration value="Leo"/>
<xsd:enumeration value="Virgo"/>
<xsd:enumeration value="Libra"/>
<xsd:enumeration value="Scorpio"/>
<xsd:enumeration value="Sagittarius"/>
<xsd:enumeration value="Capricorn"/>
<xsd:enumeration value="Aquarius"/>
<xsd:enumeration value="Pisces"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the element record, which is the only element contained inside the address_book root element whose complexType is called "addressType" --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="addressType"> <xsd:sequence> <xsd:element name="record" type="recordType"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to force the element record, whose complexType is called "recordType", to have three elements inside it, name, address, and contact, and in that order. --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="recordType"> <xsd:sequence> <xsd:element name="name" type="nameType"/> <xsd:element name="address" type="addressType"/> <xsd:element name="contact" type="contactType"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the element nick_name as a choice inside the "name" element where the complexType is named "nameType" --> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> <xsd:complexType name="nameType"> <xsd:choice> <xsd:element name="nick_name" type ="nick_nameType" /> </xsd:choice> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to allow the element name, whose complexType is called "nameType", to have the elements last_name, first_name, middle_name, and nick_name, in any order. --> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> <xsd:complexType name="nameType"> <xsd:all> <xsd:element name="last_name" type="lastNameType" minOccurs="1" maxOccurs="1" /> <xsd:element name="first_name" type="firstNameType" minOccurs="1" maxOccurs="1" /> <xsd:element name="middle_name" type="middleNameType" minOccurs="0" maxOccurs="1" /> <xsd:element name="nick_name" type="nickNameType" minOccurs="0" maxOccurs="1" /> </xsd:all> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?>
<groups>
<groupA>
<first_name>Robert</first_name>
<last_name>Cormia</last_name>
<middle_name>Douglas</middle_name>
<nick_name>Bob</nick_name>
<street>200 Woodland Vista</street>
<street_detail>PO Box 7</street_detail>
<city>La Honda</city>
<state>CA</state>
<zipcode>94020-0007</zipcode>
</groupA>
<groupB>
<street>Woodland Vista</street>
<street_detail>PO Box 7</street_detail>
<city>La Honda</city>
<state>CA</state>
<zipcode>94020-0007</zipcode>
<home_phone>800-555-1212</home_phone>
<work_phone>800-555-1212</work_phone>
<cell_phone>800-555-1212</cell_phone>
<email>rdcormia@earthlink.net</email>
<website>http://www.rdcormia.com</website>
</groupB>
</groups>
<?xml version="1.0"?> <!-- This code will be used to define the element record, which is the only element contained inside the address_book root element --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="record"> <xsd:complexType> <xsd:sequence> <xsd:group ref="name_elements"/> <xsd:group ref="address_elements"/> <xsd:group ref="contact_elements"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:group name="name_elements"> <xsd:sequence> <xsd:element name="first_name" type="xsd:string"/> <xsd:element name="last_name" type="xsd:string"/> <xsd:element name="middle_name" type="xsd:string"/> <xsd:element name="nick_name" type="xsd:string"/> </xsd:sequence> </xsd:group> <xsd:group name="address_elements"> <xsd:sequence> <xsd:element name="street" type="xsd:string"/> <xsd:element name="street_detail" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zipcode" type="xsd:string"/> </xsd:sequence> </xsd:group> <xsd:group name="contact_elements"> <xsd:sequence> <xsd:element name="home_phone" type="xsd:string"/> <xsd:element name="work_phone" type="xsd:string"/> <xsd:element name="cell_phone" type="xsd:string"/> <xsd:element name="email" type="xsd:string"/> <xsd:element name="website" type="xsd:string"/> </xsd:sequence> </xsd:group> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the element record, which is the only element contained inside the address_book root element --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="sibling" type="siblingType" /> <xsd:complexType name="siblingType"> <xsd:sequence> <xsd:element name="siblings" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to derive a text only complex type for an attribute called "year" in a element called "age"--> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="age" type="ageType" /> <xsd:complexType name="ageType"> <xsd:simpleContent> <xsd:extension base="xsd:integer"> <xsd:attribute name="year" type="xsd:date"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the attributes of dimension for the element picture, which will use a URL for the filemane and integers for dimensions of x and y--> <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"> <xsd:element name="picture" type="pictureType" /> <xsd:complexType name="pictureType"> <xsd:extension base="anyType"> <xsd:attribute name="filename" type="xsd:uri-reference"/> <xsd:attribute name="x" type="xsd:integer" /> <xsd:attribute name="y" type="xsd:integer" /> </xsd:extension> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to define the element descritpion, which will contain mixed content of two elements, one for a name and the other for a URL reference. --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="description" type="paragraph"/> <xsd:complexType name="paragraph" mixed="true"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="link" type="xsd:anyURI"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to create complex types on complex types. Here we will create declarations for birthType which is defined in birth_chracteristics --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="characteristicsType"> <xsd:sequence> <xsd:element name="height" type="xsd:string"/> <xsd:element name="weight" type="xsd:string"/> <xsd:element name="gender" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:element name="birth_characteristics" type="birthType"/> <xsd:complexType name="birthType"> <xsd:complexContent> <xsd:extension base="characteristicsType"> <xsd:sequence> <xsd:element name="mother" type="xsd:string"/> <xsd:element name="birthdate" type="xsd:date"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?> <!-- This code will be used to declare an element of complex type called "characteristics" which will contain the elements height, weight, and gender. --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="characteristics" type="characteristicsType"/> <xsd:complexType name="characteristicsType"> <xsd:sequence> <xsd:element name="height" type="xsd:string"/> <xsd:element name="weight" type="xsd:string"/> <xsd:element name="gender" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The element "picture" will have attributes for "filename", "x" pixels
and "y" pixels -->
<xsd:element name="picture">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:anyType">
<xsd:attribute name="filename" type="xsd:anyURI" use="required"/>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The element "picture" will have attributes for "filename", "x" pixels
and "y" pixels -->
<xsd:element name="picture">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:anyType">
<xsd:attribute name="filename" type="xsd:anyURI" use="required"/>
<xsd:attribute name="x" type="xsd:integer" use="optional"/>
<xsd:attribute name="y" type="xsd:integer" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- The element "citizenship" will have attribute for "country" which is predefined as "USA" --> <xsd:element name="citzenship"> <xsd:complexType> <xsd:complexContent> <xsd:extension base="xsd:anyType"> <!-- below the value for citizenship has been set as "fixed" to "USA --> <xsd:attribute name="country" type="xsd:string" fixed="USA" /> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:element> </xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The element "citizenship" will have attribute for "country" which is
predefined as "USA" -->
<xsd:element name="citzenship">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="xsd:anyType">
<!-- below the value for citizenship has been set as "default"
to "USA -->
<xsd:attribute name="country" type="xsd:string" default="USA" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The attribute group "pictureAtts" will have attributes for "filename",
"x" pixels and "y" pixels -->
<xsd:attributeGroup name="pictureAtts">
<xsd:complexType name="imagefileType">
<xsd:attribute name="filename" type="xsd:anyURI" use="required"/>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:attributeGroup>
</xsd:schema>
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- The element "picture" will reference pictureAtts attributes for "filename",
"x" pixels and "y" pixels -->
<xsd:element name="picture">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:anyType">
<xsd:attributeGroup ref="pictureAtts"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<nested_elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="nested_elements.xsd">
<outer_element block="1">
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
</outer_element>
<outer_element block="2">
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
</outer_element>
<outer_element block="3">
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
<inner_element>text goes here</inner_element>
</outer_element>
</nested_elements>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:element name="nested_elements" type="nested_elementsType">
<xsd:annotation>
<xsd:documentation>
This schema is designed around nested elements
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="nested_elementsType">
<xsd:sequence>
<xsd:element name="outer_element" type="outer_elementType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="outer_elementType">
<xsd:sequence>
<xsd:element name="inner_element" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="block" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<empty_elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="empty_elements.xsd">
<outer_element block="1">
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
</outer_element>
<outer_element block="2">
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
</outer_element>
<outer_element block="3">
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
<inner_element name="name" type="type" text="text"/>
</outer_element>
</empty_elements>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:element name="empty_elements" type="empty_elementsType">
<xsd:annotation>
<xsd:documentation>
This schema is designed around empty elements
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="empty_elementsType">
<xsd:sequence>
<xsd:element name="outer_element" type="outer_elementType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="outer_elementType">
<xsd:sequence>
<xsd:element name="inner_element" type="inner_elementType"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="block" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="inner_elementType">
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="type" type="xsd:string" use="optional"/>
<xsd:attribute name="text" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<mixed_elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="mixed_elements.xsd">
<outer_element block="1">
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
</outer_element>
<outer_element block="2">
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
</outer_element>
<outer_element block="3">
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
<inner_element name="name" type="type" text="text">inner element text</inner_element>
</outer_element>
</mixed_elements><?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:element name="mixed_elements" type="mixed_elementsType">
<xsd:annotation>
<xsd:documentation>
This schema is designed around mixed elements that contain both
elements and attributes and attributes and text
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="mixed_elementsType">
<xsd:sequence>
<xsd:element name="outer_element" type="outer_elementType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="outer_elementType">
<xsd:sequence>
<xsd:element name="inner_element" type="inner_elementType"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="block" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="inner_elementType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="type" type="xsd:string" use="optional"/>
<xsd:attribute name="text" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<story xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="story.xsd">
<chapter id="1">
<para id="1">
Some words will go here and a
<fact>will appear here</fact> and then my initials.
<name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again
<name>RDC</name>.
</para>
<para id="2">
Some words will go here and a
<fact>will appear here</fact> and then my initials.
<name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again <name>RDC</name>.
</para>
<para id="3">
Some words will go here and a <fact>will appear here</fact>
and then my initials. <name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again <name>RDC</name>.
</para>
<para id="4">
Some words will go here and a <fact>will appear here</fact>
and then my initials. <name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again <name>RDC</name>.
</para>
<para id="5">
Some words will go here and a <fact>will appear here</fact>
and then my initials. <name>RDC</name>Some more words will go here and a
<fact>will appear here</fact> and then my initials again <name>RDC</name>.
</para>
<para id="6">
And only text is in this element. So all the other elements are optional
</para>
</chapter>
</story>
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:complexType name="chapterType">
<xsd:sequence>
<xsd:element name="para" type="paraType" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:integer" use="required"/>
</xsd:complexType>
<xsd:element name="fact" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:complexType name="paraType" mixed="true">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="fact"/>
<xsd:element ref="name"/>
</xsd:choice>
<xsd:attribute name="id" type="xsd:integer" use="required"/>
</xsd:complexType>
<xsd:element name="story">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="chapter" type="chapterType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Below are the nine files that represent the address book files in nested, empty, and mixed models. These are worth viewing and comparing.