XQuery

XQuery

(pwalmsley@datypic.com)

ISBN: 0596006349

1st edition, , 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:complexType>
</xs:schema>
Table 13-3. Examples of sequence types based on name and type
ExampleExplanation
schema-element (product)+ One or more elements whose qualified name is product, that have been validated using a global element declaration in the ISSD
schema-element (prod:product) One element whose qualified name is equal to prod:product, that has been validated using a global element declaration in the ISSD
schema-attribute (prod:dept) One attribute whose qualified name is prod:dept, that has been validated using a global attribute declaration in the ISSD
element(*, prod:ProductType) One element whose type annotation is prod:ProductType or a type derived from prod:ProductType
element (prod:product, prod:ProductType) One element whose qualified name is equal to prod:product, whose type annotation is prod:ProductType or a type derived from prod:ProductType, that is in the ISSD
Datypic XQuery Services