Substitution Groups

"Substitution Groups" is a feature of the XML Schema Definition Language (XSD) that enables extensibility or flexibility within the definition of XML languages.

The substitution group mechanism allows elements within a designated group to be substituted for another element.

Elements are assigned to a group of elements that may be substituted to a particular element commonly referred to as a "head element." The substitutionGroup attribute available on xsd:element is used to add an element to a specific substitution group.

Using so-called "explicit substitution groups," a head element is defined as an "abstract" element. An abstract element has no "type". The abstract element itself, will never appear in an instance document (it won't be a data-holding element). Instead, the abstract element is a placeholder or reference to elements within a substitution group.

Using so-called "implicit substitution groups," the head element can hold data or can be replaced with an element of the Substituion Group. However, the substituting element must be of the same type as the head or of a type that was derived from the head's type.

Here's an example of something that might appear in an extension schema intended as a substitute for a Vehicle element defined within a different schema that is referenced in the example with the "abc" names pace prefix.

<xsd:complexType name="HybridVehicleType">
		<xsd:complexContent>
			<xsd:extension base="abc:VehicleType">
				<xsd:sequence>
					<xsd:element ref="VehicleFuelCellVoltage"/>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>
<xsd:element name="VehicleFuelCellVoltage" type="xsd:decimal"/>
<xsd:element name="Vehicle" type="HybridVehicleType" substitutionGroup="abc:Vehicle"/>

Thus, data in a conforming instance document, might appear as:

<ext:Vehicle>
	<abc:VehicleMake>Dodge</abc:VehicleMake>
	<abc:VehicleModel>Carvan</abc:VehicleModel>
	<abc:VehicleColor>White</abc:VehicleColor>
	<ext:VehicleFuelCellVoltage>1.1</ext:VehicleFuelCellVoltage>
</ext:Vehicle>

Trivial Example