Datypic Logo
Definitive XML Schema

Definitive XML Schema

Priscilla Walmsley (pwalmsley@datypic.com)

1st edition (December 7, 2001)

Prentice Hall PTR; ISBN: 0130655678

Chapter 18: Redefining schema components

Book examples

Example 18-1. A simple redefinition
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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
prod1.xsd:
<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>
prod2.xsd:
<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>
Datypic XML Schema Services