Chapter 35. Element Substitution
Abstract
35.1. Substitution Groups in XML Schema
Overview
Syntax
substitutionGroup attribute of the XML Schema element element. The value of the substitutionGroup attribute is the name of the element that the element being defined replaces. For example, if your head element is widget, adding the attribute substitutionGroup="widget" to an element named woodWidget specifies that anywhere a widget element is used, you can substitute a woodWidget element. This is shown in Example 35.1, “Using a Substitution Group”.
Example 35.1. Using a Substitution Group
<element name="widget" type="xsd:string" />
<element name="woodWidget" type="xsd:string"
substitutionGroup="widget" />Type restrictions
Example 35.2. Substitution Group with Complex Types
<complexType name="widgetType">
<sequence>
<element name="shape" type="xsd:string" />
<element name="color" type="xsd:string" />
</sequence>
</complexType>
<complexType name="woodWidgetType">
<complexContent>
<extension base="widgetType">
<sequence>
<element name="woodType" type="xsd:string" />
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="plasticWidgetType">
<complexContent>
<extension base="widgetType">
<sequence>
<element name="moldProcess" type="xsd:string" />
</sequence>
</extension>
</complexContent>
</complexType>
<element name="widget" type="widgetType" />
<element name="woodWidget" type="woodWidgetType"
substitutionGroup="widget" />
<element name="plasticWidget" type="plasticWidgetType"
substitutionGroup="widget" />
<complexType name="partType">
<sequence>
<element ref="widget" />
</sequence>
</complexType>
<element name="part" type="partType" />widget, is defined as being of type widgetType. Each element of the substitution group extends widgetType to include data that is specific to ordering that type of widget.
part elements in Example 35.3, “XML Document using a Substitution Group” are valid.
Example 35.3. XML Document using a Substitution Group
<part>
<widget>
<shape>round</shape>
<color>blue</color>
</widget>
</part>
<part>
<plasticWidget>
<shape>round</shape>
<color>blue</color>
<moldProcess>sandCast</moldProcess>
</plasticWidget>
</part>
<part>
<woodWidget>
<shape>round</shape>
<color>blue</color>
<woodType>elm</woodType>
</woodWidget>
</part>Abstract head elements
abstract attribute of an element element to true, as shown in Example 35.4, “Abstract Head Definition”. Using this schema, a valid review element can contain either a positiveComment element or a negativeComment element, but cannot contain a comment element.
Example 35.4. Abstract Head Definition
<element name="comment" type="xsd:string" abstract="true" />
<element name="positiveComment" type="xsd:string"
substitutionGroup="comment" />
<element name="negtiveComment" type="xsd:string"
substitutionGroup="comment" />
<element name="review">
<complexContent>
<all>
<element name="custName" type="xsd:string" />
<element name="impression" ref="comment" />
</all>
</complexContent>
</element>
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.