Lists Home |
Date Index |
Dan White writes:
> I have a situation where the incoming XML will have an element/attribute
> specifying one of four enumerated choices. Depending on the value of that
> choice, the elements that follow will be different.
> Like this:
> <foo mode="one">
> <foo mode="two">
> How does one set up the schema to validate the appropriate sequence of
> elements based on the value of the "controlling" element/attribute ?
If you are committed to the particular attribute names or the use of elements,
then you cannot do this with XML Schema. You could layer Schematron or
something similar on top of it.
If you use xsi:type as your attribute, you can get the effect of this by
defining a type for each of the variants and using the name of that type as the
value of the xsi:type attribute. The types will all have to derive from a
common base, but that base can be nothing, and they can all extend from it.
Or, you can use different element names for the different variants, drop the
extra attribute and use substitution groups, e.g.
The deal with substitution groups is that you don't have to put a big explicit
choice into the element that uses these, but just ref the root of the
See http://www.mathling.com/xsd/ for gory details and extended examples.