 |
 |
 |
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</mode>
> <data1>aaa</data1>
> <data2>bbb</data2>
> </foo
>
> <foo>
> <mode>two</mode>
> <data3>ccc</data3>
> <data4>ddd</data4>
> </foo>
>
> or
> <foo mode="one">
> <data1>aaa</data1>
> <data2>bbb</data2>
> </foo
>
> <foo mode="two">
> <data3>ccc</data3>
> <data4>ddd</data4>
> </foo>
>
> 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.
<one>
<data1>aaa</data1>
<data2>bbb</data2>
</one>
<two>
<data3>ccc</data3>
<data4>ddd</data4>
</two>
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
substitution group.
See http://www.mathling.com/xsd/ for gory details and extended examples.
-- Mary
Holstege@m...
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |