Element Substitution Groups

Substitution groups are very similar to choice types. They allow a given base element (referred to as the substitution group head) to be replaced with a different element. The replacement element is designated as being part of the group through the use of the XSD substitutionGroup attribute.

For example, the following element declarations declare a group in which the head element (Publication) would be replaced with either the Book element or Magazine element:

   <xsd:element name="Publication" abstract="true"
   type="PublicationType"/>

   <xsd:element name="Book" substitutionGroup="Publication"
   type="BookType"/>

   <xsd:element name="Magazine" substitutionGroup="Publication"
   type="MagazineType"/>

In these declarations, the types BookTypeand MagazineTypemust be derived from the substitution group head type (in this case, PublicationType). This now allows Book or Magazine to be used anywhere Publication was declared to be used (in fact, the elements in this case must be Book or Magazine because Publication was declared to be abstract and therefore cannot appear in an XML instance).

XBinder generates a special group class to hold each of the substitution group alternative elements. This class is generated as for an <xsd:choice> whose particles consist of each of the elements in the substitution group. The format of the name for the special group class is "_<element>SG", where <element> would be replaced with the name of the substitution group head element. In the example above, the generated type name would be "_PublicationSG".