Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema : substitution groups

Tags:

xml

schema

I'm investigating substitution groups in XML schema and I can't seem to find the official spec. can anyone point me to it ?

I'm wondering if an element with substitution group attribute can replace an element inside a complex or only global elements as w3schools claims :

"Note that all elements in the substitutionGroup (the head element and the substitutable elements) must be declared as global elements, otherwise it will not work!"

is the above statement true ?

since global elements can each be a root of the XML instance - what is the point of defining substitution groups on them ?

like image 531
Gady Avatar asked Nov 16 '09 11:11

Gady


1 Answers

Substitution groups are a very complex beast. Essentially, what it gives is an alternative way of expressing <xs:choice> structures, without having to list all of the possible choices. This means you can come along at a later date and additional options to the choice, without having to modify the original schema.

The use cases where this is actually useful are very few and far between, being limited to schemas that are designed to be extensible by 3rd parties. In reality, they are very hard to work with, and very hard to understand (see here for more reasons to avoid them).

like image 63
skaffman Avatar answered Oct 20 '22 00:10

skaffman