tags:

views:

99

answers:

1

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 ?

A: 

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).

skaffman
this is true, but I'm writing a tool that needs to support substitution groups. can you point me to the spec ?
Gady
Well the spec is at http://www.w3.org/TR/2001/REC-xmlschema-0-20010502/#SubsGroups. Good luck making any sense out of it, though.
skaffman
I think it depends. Using substitution groups on an abstract "parent" element produces nicer JAXB generated classes than using choice or sequences.
Marc