Datypic Logo
Definitive XML Schema

Definitive XML Schema

Priscilla Walmsley (pwalmsley@datypic.com)

2nd edition (September 2012)

Prentice Hall PTR; ISBN: 0132886723

Chapter 13: Deriving complex types

Full Example

This example illustrates complex types that are derived from other specified types.

Instance (chapter13.xml)

<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="chapter14.xsd">
  <hat routingNum="123456" effDate="2002-04-02" lang="en-US">
    <number>557</number>
    <name>Ten-Gallon Hat</name>
    <description>This is a great hat!</description>
  </hat>
  <umbrella routingNum="123" effDate="2002-04-02">
    <number>557</number>
    <name>Ten-Gallon Hat</name>
  </umbrella>
  <shirt routingNum="124" effDate="2002-04-02" sleeve="17">
    <number>557</number>
    <name>Short-Sleeved Linen Blouse</name>
    <color value="blue"/>
    <size system="US-DRESS">6</size>
  </shirt>
</items>

Schema (chapter13.xsd)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="items" type="ItemsType"/>
  <xs:complexType name="ItemsType">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="hat" type="ProductType"/>
      <xs:element name="umbrella" type="RestrictedProductType"/>
      <xs:element name="shirt" type="ShirtType"/>
    </xs:choice>
  </xs:complexType>
  <!--Empty Content Type-->
  <xs:complexType name="ItemType" abstract="true">
    <xs:attribute name="routingNum" type="xs:integer"/>
  </xs:complexType>
  <!--Empty Content Extension (with Attribute Extension)-->
  <xs:complexType name="ProductType">
    <xs:complexContent>
      <xs:extension base="ItemType">
        <xs:sequence>
          <xs:element name="number" type="xs:integer"/>
          <xs:element name="name" type="xs:string"/>
          <xs:element name="description"
                       type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="effDate" type="xs:date"/>
        <xs:attribute name="lang" type="xs:language"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!--Complex Content Restriction-->
  <xs:complexType name="RestrictedProductType">
    <xs:complexContent>
      <xs:restriction base="ProductType">
        <xs:sequence>
          <xs:element name="number" type="xs:integer"/>
          <xs:element name="name" type="xs:token"/>
        </xs:sequence>
        <xs:attribute name="routingNum"
                       type="xs:short" use="required"/>
        <xs:attribute name="effDate"
                       type="xs:date" default="1900-01-01"/>
        <xs:attribute name="lang" use="prohibited"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
  <!--Complex Content Extension-->
  <xs:complexType name="ShirtType">
    <xs:complexContent>
      <xs:extension base="RestrictedProductType">
        <xs:choice maxOccurs="unbounded">
          <xs:element name="size" type="SmallSizeType"/>
          <xs:element name="color" type="ColorType"/>
        </xs:choice>
        <xs:attribute name="sleeve" type="xs:integer"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <!--Simple Content Extension-->
  <xs:complexType name="SizeType">
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name="system" type="xs:token"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <!--Simple Content Restriction-->
  <xs:complexType name="SmallSizeType">
    <xs:simpleContent>
      <xs:restriction base="SizeType">
        <xs:minInclusive value="2"/>
        <xs:maxInclusive value="6"/>
        <xs:attribute  name="system" type="xs:token"
                        use="required"/>
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="ColorType">
    <xs:attribute name="value" type="xs:string"/>
  </xs:complexType>
</xs:schema>

Book Examples

Example 13-1. Simple content extension

Schema:

<xs:complexType name="SizeType">
  <xs:simpleContent>
    <xs:extension base="xs:integer">
      <xs:attribute name="system" type="xs:token"/>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

Instance:

<size system="US-DRESS">10</size>

Example 13-2. Complex content extension

<xs:complexType name="ProductType">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="ShirtType">
  <xs:complexContent>
    <xs:extension base="ProductType">
      <xs:choice maxOccurs="unbounded">
        <xs:element name="size" type="xs:integer"/>
        <xs:element name="color" type="xs:string"/>
      </xs:choice>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-3. Effective content model of ShirtType

<xs:complexType name="ShirtType">
  <xs:sequence>
    <xs:sequence>
      <xs:element name="number" type="xs:integer"/>
      <xs:element name="name" type="xs:string"/>
    </xs:sequence>
    <xs:choice maxOccurs="unbounded">
      <xs:element name="size" type="xs:integer"/>
      <xs:element name="color" type="xs:string"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>

Example 13-4. choice group extension

<xs:complexType name="ItemsType">
  <xs:choice maxOccurs="unbounded">
    <xs:element ref="shirt"/>
    <xs:element ref="hat"/>
    <xs:element ref="umbrella"/>
  </xs:choice>
</xs:complexType>
<xs:complexType name="ExpandedItemsType">
  <xs:complexContent>
    <xs:extension base="ItemsType">
      <xs:choice maxOccurs="unbounded">
        <xs:element ref="sweater"/>
        <xs:element ref="suit"/>
      </xs:choice>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-5. all group extension

<xs:complexType name="ProductType">
  <xs:all>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:all>
</xs:complexType>
<xs:complexType name="ShirtType">
  <xs:complexContent>
    <xs:extension base="ProductType">
      <xs:all>
        <xs:element name="size" type="xs:integer"/>
        <xs:element name="color" type="xs:string"/>
      </xs:all>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-6. Effective content model of ShirtType with all groups combined

<xs:complexType name="ShirtType">
  <xs:all>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="size" type="xs:integer"/>
    <xs:element name="color" type="xs:string"/>
  </xs:all>
</xs:complexType>

Example 13-7. Extending open content

<xs:complexType name="ProductType">
  <xs:openContent mode="suffix">
    <xs:any namespace="##other" processContents="lax"/>
  </xs:openContent>
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="ShirtType">
  <xs:complexContent>
    <xs:extension base="ProductType">
      <xs:openContent mode="suffix">
        <xs:any namespace="##any" processContents="lax"/>
      </xs:openContent>
      <xs:sequence>
        <xs:element name="size" type="xs:integer"/>
        <xs:element name="color" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-8. Mixed content extension

<xs:complexType name="LetterType" mixed="true">
  <xs:sequence>
    <xs:element name="custName" type="xs:string"/>
    <xs:element name="prodName" type="xs:string"/>
    <xs:element name="prodSize" type="xs:integer"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="ExtendedLetterType" mixed="true">
  <xs:complexContent>
    <xs:extension base="LetterType">
      <xs:sequence>
        <xs:element name="prodNum" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-9. Empty content extension

<xs:complexType name="ItemType">
  <xs:attribute name="routingNum" type="xs:integer"/>
</xs:complexType>

Example 13-10. Attribute extension

Schema:

<xs:complexType name="ItemType">
  <xs:attribute name="id" type="xs:ID" use="required"/>
  <xs:attribute ref="xml:lang"/>
</xs:complexType>

Example 13-11. Attribute wildcard extension

<xs:complexType name="BaseType">
  <xs:anyAttribute processContents="lax"
                   namespace="##local
                              http://datypic.com/prod"/>
</xs:complexType>
<xs:complexType name="DerivedType">
  <xs:complexContent>
    <xs:extension base="BaseType">
      <xs:anyAttribute processContents="strict"
                       namespace="##targetNamespace
                                  http://www.w3.org/1999/xhtml"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Example 13-12. Effective attribute wildcard

<xs:complexType name="DerivedType">
  <xs:anyAttribute processContents="strict"
                   namespace="##local
                              http://datypic.com/prod
                              ##targetNamespace
                              http://www.w3.org/1999/xhtml"/>
</xs:complexType>

Example 13-13. Simple content restriction

<xs:complexType name="SmallSizeType">
  <xs:simpleContent>
    <xs:restriction base="SizeType">
      <xs:minInclusive value="2"/>
      <xs:maxInclusive value="6"/>
      <xs:attribute name="system" type="xs:token"
                    use="required"/>
    </xs:restriction>
  </xs:simpleContent>
</xs:complexType>

Example 13-14. Complex content restriction

<xs:complexType name="ProductType">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="size" type="xs:integer" minOccurs="0"/>
    <xs:element name="color" type="xs:string" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="RestrictedProductType">
  <xs:complexContent>
    <xs:restriction base="ProductType">
      <xs:sequence>
        <xs:element name="number" type="xs:integer"/>
        <xs:element name="name" type="xs:string"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-15. Eliminating meaningless groups

Base group:

<xs:sequence>
  <xs:sequence>
    <xs:element name="a"/>
    <xs:element name="b"/>
  </xs:sequence>
</xs:sequence>

Legal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="b"/>
</xs:sequence>

Example 13-16. Restricting element declarations

Base group:

<xs:sequence>
  <xs:element name="a" maxOccurs="3"/>
  <xs:element name="b" fixed="bValue"/>
  <xs:element name="c" type="xs:string"/>
</xs:sequence>

Legal restriction:

<xs:sequence>
  <xs:element name="a" maxOccurs="2"/>
  <xs:element name="b" fixed="bValue"/>
  <xs:element name="c" type="xs:token"/>
</xs:sequence>

Illegal restriction:

<xs:sequence>
  <xs:element name="a" maxOccurs="4"/>
  <xs:element name="b" fixed="newValue"/>
  <xs:element name="c" type="xs:integer"/>
</xs:sequence>

Example 13-17. Replacing a wildcard with element declarations

Base group:

<xs:sequence>
  <xs:element name="a"/>
  <xs:any namespace="##other" maxOccurs="1"/>
</xs:sequence>

Legal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element ref="otherns:b"/>
</xs:sequence>

Illegal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element ref="b"/>
  <xs:element name="c"/>
</xs:sequence>

Example 13-18. Replacing a wildcard with another wildcard

Base wildcard:

<xs:any namespace="urn:a:1 urn:a:2" maxOccurs="2"/>

Legal restriction:

<xs:any namespace="urn:a:1" maxOccurs="1"/>

Illegal restriction:

<xs:any namespace="##other" maxOccurs="3"/>

Example 13-19. Replacing a group with an element declaration

Base group:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="b" minOccurs="0"/>
</xs:sequence>

Legal restriction:

<xs:element name="a"/>

Example 13-20. Restricting occurrence constraints of a group

Base group:

<xs:sequence minOccurs="2" maxOccurs="5">
  <xs:element name="a"/>
  <xs:element name="b"/>
</xs:sequence>

Legal restriction:

<xs:sequence minOccurs="3" maxOccurs="4">
  <xs:element name="a"/>
  <xs:element name="b"/>
</xs:sequence>

Illegal restriction:

<xs:sequence minOccurs="0" maxOccurs="6">
  <xs:element name="a"/>
  <xs:element name="b"/>
</xs:sequence>

Example 13-21. Maintaining the order of the children in an all group

Base group:

<xs:all>
  <xs:element name="a"/>
  <xs:element name="b" minOccurs="0"/>
  <xs:element name="c"/>
</xs:all>

Example 13-22. Restricting an all group

Base group:

<xs:all>
  <xs:element name="a"/>
  <xs:element name="b" minOccurs="0"/>
  <xs:element name="c"/>
</xs:all>

Legal restriction:

<xs:all>
  <xs:element name="a"/>
  <xs:element name="c"/>
</xs:all>

Example 13-23. Restricting a choice group

Base group:

<xs:choice>
  <xs:element name="a"/>
  <xs:element name="b"/>
  <xs:element name="c"/>
</xs:choice>

Legal restriction:

<xs:choice>
  <xs:element name="a"/>
  <xs:element name="c"/>
</xs:choice>

Illegal restriction:

<xs:choice>
  <xs:element name="a"/>
  <xs:element name="d"/>
</xs:choice>

Example 13-24. Replacing an all group with a sequence group

Base group:

<xs:all>
  <xs:element name="a"/>
  <xs:element name="b" minOccurs="0"/>
  <xs:element name="c"/>
</xs:all>

Legal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="c"/>
</xs:sequence>

Illegal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="b"/>
  <xs:element name="c" minOccurs="2"/>
</xs:sequence>

Example 13-25. Replacing a choice group with a sequence group

Base group:

<xs:choice maxOccurs="2">
  <xs:element name="a"/>
  <xs:element name="b"/>
  <xs:element name="c"/>
</xs:choice>

Legal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="c"/>
</xs:sequence>

Illegal restriction:

<xs:sequence>
  <xs:element name="a"/>
  <xs:element name="b"/>
  <xs:element name="c"/>
</xs:sequence>

Example 13-26. Restricting open content

Base group:

<xs:complexType name="BaseType">
  <xs:openContent mode="suffix">
    <xs:any namespace="http://datypic.com/prod
                       http://datypic.com/ord"/>
  </xs:openContent>
  <xs:sequence>
    <xs:element name="a" type="xs:string" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>

Legal restriction:

<xs:complexType name="LegalDerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType">
      <xs:openContent mode="suffix">
        <xs:any namespace="http://datypic.com/prod"/>
      </xs:openContent>
      <xs:sequence>
        <xs:element name="a" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Illegal restriction:

<xs:complexType name="IllegalDerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType">
      <xs:openContent mode="interleave">
        <xs:any namespace="##any"/>
      </xs:openContent>
      <xs:sequence>
        <xs:element name="a" type="xs:string" minOccurs="0"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-27. Mixed content restriction

<xs:complexType name="LetterType" mixed="true">
  <xs:sequence>
    <xs:element name="custName" type="xs:string"/>
    <xs:element name="prodName" type="xs:string"/>
    <xs:element name="prodSize" type="xs:integer" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="RestrictedLetterType" mixed="true">
  <xs:complexContent>
    <xs:restriction base="LetterType">
      <xs:sequence>
        <xs:element name="custName" type="xs:string"/>
        <xs:element name="prodName" type="xs:string"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-28. Mixed content restricted to simple content

<xs:complexType name="LetterType" mixed="true">
  <xs:sequence minOccurs="0">
    <xs:element name="custName" type="xs:string"/>
    <xs:element name="prodName" type="xs:string"/>
    <xs:element name="prodSize" type="xs:integer"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="RestrictedLetterType">
  <xs:simpleContent>
    <xs:restriction base="LetterType">
      <xs:simpleType>
        <xs:restriction base="xs:string"/>
      </xs:simpleType>
    </xs:restriction>
  </xs:simpleContent>
</xs:complexType>

Example 13-29. Empty content restriction

<xs:complexType name="ItemType">
  <xs:attribute name="routingNum" type="xs:integer"/>
</xs:complexType>
<xs:complexType name="RestrictedItemType">
  <xs:complexContent>
    <xs:restriction base="ItemType">
      <xs:attribute name="routingNum" type="xs:short"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-30. Legal restrictions of attributes

<xs:complexType name="BaseType">
      <xs:attribute name="a" type="xs:integer"/>
      <xs:attribute name="b" type="xs:string"/>
      <xs:attribute name="c" type="xs:string" default="c"/>
      <xs:attribute name="d" type="xs:string"/>
      <xs:attribute name="e" type="xs:string" fixed="e"/>
      <xs:attribute name="f" type="xs:string"/>
      <xs:attribute name="g" type="xs:string"/>
      <xs:attribute name="x" type="xs:string"/>
</xs:complexType>
<xs:complexType name="DerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType">
      <xs:attribute name="a" type="xs:positiveInteger"/>
      <xs:attribute name="b" type="xs:string" default="b"/>
      <xs:attribute name="c" type="xs:string" default="c2"/>
      <xs:attribute name="d" type="xs:string" fixed="d"/>
      <xs:attribute name="e" type="xs:string" fixed="e"/>
      <xs:attribute name="f" type="xs:string" use="required"/>
      <xs:attribute name="g" type="xs:string" use="prohibited"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-31. Illegal attribute restrictions

<xs:complexType name="BaseType2">
      <xs:attribute name="h" type="xs:integer"/>
      <xs:attribute name="i" type="xs:string" fixed="i"/>
      <xs:attribute name="j" type="xs:string" fixed="j"/>
      <xs:attribute name="k" type="xs:string" use="required"/>
      <xs:attribute name="l" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="IllegalDerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType2">
      <xs:attribute name="h" type="xs:decimal"/>
      <xs:attribute name="i" type="xs:string" fixed="i2"/>
      <xs:attribute name="j" type="xs:string" default="j"/>
      <xs:attribute name="k" type="xs:string"/>
      <xs:attribute name="l" type="xs:string" use="prohibited"/>
      <xs:attribute ref="pref:l"/>
      <xs:attribute name="m" type="xs:string"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-32. Restricting an attribute wildcard

<xs:complexType name="BaseType">
  <xs:anyAttribute processContents="lax" namespace="##any"/>
</xs:complexType>
<xs:complexType name="DerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType">
      <xs:anyAttribute processContents="strict"
                       namespace="##targetNamespace
                                  http://www.w3.org/1999/xhtml"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-33. Replacing an attribute wildcard with attributes

<xs:complexType name="BaseType">
  <xs:anyAttribute processContents="lax" namespace="##any"/>
</xs:complexType>
<xs:complexType name="DerivedType">
  <xs:complexContent>
    <xs:restriction base="BaseType">
      <xs:attribute name="id" type="xs:ID" use="required"/>
      <xs:attribute name="name" type="xs:string"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Example 13-34. Restricting a type from another namespace with global declarations

prod.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://datypic.com/prod"
           xmlns:prod="http://datypic.com/prod"
           elementFormDefault="qualified"
           attributeFormDefault="qualified">
  <xs:complexType name="ProductType">
    <xs:sequence>
      <xs:element ref="prod:number"/>
      <xs:element ref="prod:name"/>
      <xs:element ref="prod:size" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute ref="prod:dept"/>
  </xs:complexType>
  <xs:element name="number" type="xs:integer"/>
  <xs:element name="name" type="xs:string"/>
  <xs:element name="size" type="xs:integer"/>
  <xs:attribute name="dept" type="xs:string"/>
</xs:schema>

ord.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://datypic.com/ord"
           xmlns:prod="http://datypic.com/prod">
  <xs:import namespace="http://datypic.com/prod"
             schemaLocation="prod.xsd"/>
  <xs:complexType name="RestrictedProductType">
    <xs:complexContent>
      <xs:restriction base="prod:ProductType">
        <xs:sequence>
          <xs:element ref="prod:number"/>
          <xs:element ref="prod:name"/>
        </xs:sequence>
        <xs:attribute ref="prod:dept" use="required"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

Example 13-35. Using targetNamespace on element and attribute declarations

prod.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://datypic.com/prod"
           elementFormDefault="qualified"
           attributeFormDefault="qualified">
  <xs:complexType name="ProductType">
    <xs:sequence>
      <xs:element name="number" type="xs:integer"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="size" type="xs:integer" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="dept" type="xs:string"/>
  </xs:complexType>
</xs:schema>

ord.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://datypic.com/ord"
           xmlns:prod="http://datypic.com/prod"
           elementFormDefault="qualified"
           attributeFormDefault="qualified">
  <xs:import namespace="http://datypic.com/prod"
             schemaLocation="prod.xsd"/>
  <xs:complexType name="RestrictedProductType">
    <xs:complexContent>
      <xs:restriction base="prod:ProductType">
        <xs:sequence>
          <xs:element name="number" type="xs:integer"
                      targetNamespace="http://datypic.com/prod"/>
          <xs:element name="name" type="xs:string"
                      targetNamespace="http://datypic.com/prod"/>
        </xs:sequence>
        <xs:attribute name="dept" type="xs:string" use="required"
                      targetNamespace="http://datypic.com/prod"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

Example 13-36. A derived type

<xs:complexType name="ProductType">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="product" type="ProductType"/>

Example 13-37. Substitution of ShirtType for ProductType

<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <product xsi:type="ShirtType">
    <number>557</number>
    <name>Short-Sleeved Linen Blouse</name>
    <color>blue</color>
  </product>
  <!--...-->
</items>

Example 13-38. Preventing derivation

<xs:complexType name="ProductType" final="#all">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

Example 13-39. Preventing substitution of derived types

<xs:complexType name="ProductType" block="extension">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="product" type="ProductType"/>
<xs:complexType name="ShirtType">
  <xs:complexContent>
    <xs:extension base="ProductType">
      <xs:choice maxOccurs="unbounded">
        <xs:element name="size" type="xs:integer"/>
        <xs:element name="color" type="xs:string"/>
      </xs:choice>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
<xs:element name="shirt" type="ShirtType"/>

Example 13-40. Illegal substitution of ShirtType

<product xsi:type="ShirtType">
  <number>557</number>
  <name>Short-Sleeved Linen Blouse</name>
  <color>blue</color>
</product>

Example 13-41. An abstract type

<xs:complexType name="ProductType" abstract="true">
  <xs:sequence>
    <xs:element name="number" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="product" type="ProductType"/>
<xs:complexType name="ShirtType">
  <xs:complexContent>
    <xs:extension base="ProductType">
      <xs:choice maxOccurs="unbounded">
        <xs:element name="size" type="xs:integer"/>
        <xs:element name="color" type="xs:string"/>
      </xs:choice>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
<xs:element name="shirt" type="ShirtType"/>

Example 13-42. Legal instances of product and shirt

<product xsi:type="ShirtType">
  <number>557</number>
  <name>Short-Sleeved Linen Blouse</name>
  <color>blue</color>
</product>
<shirt>
  <number>557</number>
  <name>Short-Sleeved Linen Blouse</name>
  <color>blue</color>
</shirt>

Example 13-43. Illegal uses of the abstract ProductType

<product>
  <number>557</number>
  <name>Short-Sleeved Linen Blouse</name>
</product>
<product xsi:type="ProductType">
  <number>557</number>
  <name>Short-Sleeved Linen Blouse</name>
</product>