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> ...

Get Special Edition Using XML, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.