O'Reilly logo

Special Edition Using XML, Second Edition by - et al. David Gulbransen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Substitution Groups

One new powerful feature of XML Schemas is a Substitution group, which is simply a grouping of elements that can be substituted for one another. The element that serves as the basis for the group is called the head element. Let's look at an example:

<xs:element name="customer" type="xs:string" /> 
<xs:element name="myspace:phone" type="xs:string" />

<xs:element name="USphone" type="xs:string"
        substitutionGroup="myspace:phone"/>

<xs:element name="INTphone" type="xs:string"
        substitutionGroup="myspace:phone"/>

<xs:element name="contact">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="customer"/>
      <xs:element ref="myspace:phone"/>
    </xs:sequence>
  <xs:complexType>
</xs:element>

In this example, we start by declaring a <customer> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required