Another XSD question - how can I achieve that the following XML elements are both valid:
<some-element>
<type>1</type>
<a>...</a>
</some-element>
<some-element>
<type>2</type>
<b>...</b>
</some-element>
The sub-elements (either <a>
or <b>
) should depend on the content of <type>
(could also be an attribute). It would be so simple in RelaxNG - but RelaxNG doesn't support key integrity :(
Is there a way to implement this in XSD?
Note: XML schema version 1.1 supports <xs:alternative>
, which might be a solution, but afaik no reference implementation (e.g. libxml2) supports this yet. So I'm searching for workarounds. The only way I've come up with is:
<type>1</type>
<some-element type="1">
<!-- simple <xs:choice> between <a> and <b> goes here -->
<a>...</a>
</some-element>
<!-- and now create a keyref between <type> and @type -->