15.2.17. XSD element substitution (Element Substitution)

发布时间 :2025-10-25 12:23:25 UTC      

With XML Schema, one element can be replaced by another.

Element substitution

Let’s give an example: our users are from the UK and Norway. We want to be able to give users the ability to choose whether to use Norwegian or English element names in XML documents.

To solve this problem, we can define a substitutionGroup . First, we declare the primary element, and then we declare the secondary elements, which can declare that they can replace the primary element.

<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/>

In the above example, the “name” element is the main element, while the “navn” element replaces the “name” element.

Take a look at a clip of XML schema:

<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/>
<xs:complexType name="custinfo">
  <xs:sequence>
    <xs:element ref="name"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo"/>
<xs:element name="kunde" substitutionGroup="customer"/>

A valid XML document looks like this (according to the schema above):

<customer>
  <name>John Smith</name>
</customer>

Or something like this:

<kunde>
  <navn>John Smith</navn>
</kunde>

Prevent element substitution

To prevent other elements from replacing a specified element, use the block attribute:

<xs:element name="name" type="xs:string" block="substitution"/>

Take a look at a clip of a XML schema:

<xs:element name="name" type="xs:string" block="substitution"/>
<xs:element name="navn" substitutionGroup="name"/>
<xs:complexType name="custinfo">
  <xs:sequence>
    <xs:element ref="name"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo" block="substitution"/>
<xs:element name="kunde" substitutionGroup="customer"/>

A legitimate XML document should look like this (according to the schema above):

<customer>
  <name>John Smith</name>
</customer>

But the following documents are no longer legal:

<kunde>
  <navn>John Smith</navn>
</kunde>

Use substitutionGroup

The type of the replaceable element must be the same as or derived from the parent element. If the type of the replaceable element is the same as the type of the main element, you do not have to specify the type of the replaceable element.

Note that all elements in the substitutionGroup (primary and replaceable elements) must be declared as global elements or they will not work!

What is a global element (Global Elements)?

The global element refers to the immediate child element of the “schema” element! Local elements (Local elements) refer to elements that are nested within other elements.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.