The best Replace XML Schema elements Tutorial In 2024, In this tutorial you can learn Replaced elements,Replace stop element,Use substitutionGroup,What is the global element (Global Elements)?,
By XML Schema, an element can be replaced with another element.
Let us illustrate: our customers from the UK and Norway. We want to have the ability to let users choose to use the Norwegian element names in the XML document or the English name of the element.
To solve this problem, we can define a substitutionGroup in the XML schema. First, we declare the main element, then we will declare minor elements, these elements can be declared once they are able to replace the primary element.
In the above example, "name" element is the main element, "navn" element can replace "name" element.
Consider a XML schema fragment:
Valid XML document like this (according to the above schema):
Or something like this:
To prevent other elements replace a specified element, use the block properties:
See an XML schema fragment:
Valid XML document should look like this (according to the above schema):
However, the following document is no longer legitimate:
Replaceable elements must be the main elements of the same type, or derived from the main element. If the type can replace elements of the main elements of the same type, you will not have to specify the type of the element can be replaced.
Please note, substitutionGroup all elements in the (primary elements and replaceable elements) must be declared as global elements, otherwise it will not work!
Global element refers to the direct child elements of "schema" element! Local elements (Local elements) refers to the elements nested within other elements.