XQuery
Priscilla Walmsley (pwalmsley@datypic.com)ISBN: 0596006349
1st edition, 2007, O'Reilly Media, Inc.
Chapter 13: Using Schemas with XQuery
Example 13-1. Schema for catalog.xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="catalog" type="CatalogType"/>
<xs:complexType name="CatalogType">
<xs:sequence>
<xs:element ref="product" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="product" type="ProductType"/>
<xs:complexType name="ProductType">
<xs:sequence>
<xs:element name="number" type="xs:integer"/>
<xs:element name="name" type="NameType"/>
<xs:element name="colorChoices" type="ColorListType" minOccurs="0"/>
<xs:element name="desc" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="dept" type="xs:string"/>
</xs:complexType>
<xs:simpleType name="ColorListType">
<xs:list itemType="xs:string"/>
</xs:simpleType>
<xs:complexType name="NameType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="LangType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="LangType">
<xs:restriction base="xs:string">
<xs:enumeration value="en"/>
<xs:enumeration value="fr"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Example 13-2. Beginning of the catalog schema with target namespace
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://datypic.com/prod"
xmlns:prod="http://datypic.com/prod">
<xs:element name="catalog" type="prod:CatalogType"/>
<xs:complexType name="CatalogType">
<!-- ... -->
</xs:schema>
