D A T Y P I C
home
services
books
Overview
Table of Contents
Sample Chapter
Examples
1. Intro
2. Quick tour
3. Namespaces
4. Include/Import
5. Instances
6. Annotations
7. Element Decls
8. Attribute Decls
9. Simple types
10. Regexes
11. Union/List types
12. Built-in types
13. Complex types
14. Type derivation
15. Groups
16. Subst. groups
17. ID constraints
18. Redefines
19. DTDs topics
20. Naming
21. Extensibility
Errata
about
Definitive XML Schema

Definitive XML Schema

Priscilla Walmsley (pwalmsley@datypic.com)
1st edition (December 7, 2001)
Prentice Hall PTR; ISBN: 0130655678
Amazon.com
Buy at 30% off list price


Chapter 18: Redefining schema components


Book Examples

Example 18-1. A simple redefinition

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:simpleType name="DressSizeType">
    <xsd:restriction base="xsd:integer"/>
  </xsd:simpleType>

  <xsd:element name="size" type="DressSizeType"/>

  <xsd:element name="color" type="xsd:string"/>

</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://example.org/prod"
            targetNamespace="http://example.org/prod">

  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:simpleType name="DressSizeType">
      <xsd:restriction base="DressSizeType">
        <xsd:minInclusive value="2"/>
        <xsd:maxInclusive value="16"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:redefine>

  <xsd:element name="newSize" type="DressSizeType"/>

</xsd:schema>


Example 18-2. Redefining a simple type

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:simpleType name="DressSizeType">
    <xsd:restriction base="xsd:integer">
      <xsd:minInclusive value="0"/>
      <xsd:maxInclusive value="18"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="size" type="DressSizeType"/>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:simpleType name="DressSizeType">
      <xsd:restriction base="DressSizeType">
        <xsd:minInclusive value="2"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:redefine>
  <xsd:element name="newSize" type="DressSizeType"/>
</xsd:schema>


Example 18-3. Redefining a complex type

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="ProductType">
    <xsd:sequence>
      <xsd:element name="number" type="ProdNumType"/>
      <xsd:element name="name" type="xsd:string"/>
      <xsd:element name="size" type="SizeType"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:complexType name="ProductType">
      <xsd:complexContent>
        <xsd:extension base="ProductType">
          <xsd:sequence>
            <xsd:element name="color" type="ColorType"/>
          </xsd:sequence>
          <xsd:attribute name="effDate" type="xsd:date"/>
        </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType>
  </xsd:redefine>
</xsd:schema>


Example 18-4. Redefining a named model group as a subset

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:group name="DescriptionGroup">
    <xsd:sequence>
      <xsd:element name="description" type="xsd:string"/>
      <xsd:element name="comment" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
  </xsd:group>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:group name="DescriptionGroup">
      <xsd:sequence>
        <xsd:element name="description" type="xsd:string"/>
      </xsd:sequence>
    </xsd:group>
  </xsd:redefine>
</xsd:schema>


Example 18-5. Redefining a named model group as a superset

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:group name="DescriptionGroup">
    <xsd:sequence>
      <xsd:element name="description" type="xsd:string"/>
      <xsd:element name="comment" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
  </xsd:group>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:group name="DescriptionGroup">
      <xsd:sequence>
        <xsd:group ref="DescriptionGroup"/>
        <xsd:element name="notes" type="xsd:string"/>
      </xsd:sequence>
    </xsd:group>
  </xsd:redefine>
</xsd:schema>


Example 18-6. Redefining an attribute group as a subset

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:attributeGroup name="IdentifierGroup">
    <xsd:attribute name="id" type="xsd:ID" use="required"/>
    <xsd:attribute name="version" type="xsd:decimal"/>
    <xsd:attribute ref="xml:lang"/>
  </xsd:attributeGroup>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:attributeGroup name="IdentifierGroup">
      <xsd:attribute name="id" type="xsd:ID" use="required"/>
      <xsd:attribute name="version" type="xsd:integer"/>
    </xsd:attributeGroup>
  </xsd:redefine>
</xsd:schema>


Example 18-7. Redefining an attribute group as a superset

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
  <xsd:attributeGroup name="IdentifierGroup">
    <xsd:attribute name="id" type="xsd:ID" use="required"/>
    <xsd:attribute name="version" type="xsd:decimal"/>
    <xsd:attribute ref="xml:lang"/>
  </xsd:attributeGroup>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:redefine schemaLocation="prod1.xsd">
    <xsd:attributeGroup name="IdentifierGroup">
      <xsd:attributeGroup ref="IdentifierGroup"/>
      <xsd:attribute name="effDate" type="xsd:date"/>
    </xsd:attributeGroup>
  </xsd:redefine>
</xsd:schema>