tags:

views:

545

answers:

1

I want to construct the following XML:

<?xml version="1.0"?>
<foo>
  <bar type="alpha">
    <first />
    <second />
  </bar>
  <bar type="bravo">
    <third />
    <fourth />
  </bar>
</foo>

The salient point being that I want "bar" to have different child elements depending on its type -- if the type is "alpha" then the children MUST be "first" and "second", and if the type is "bravo" then the children MUST be "third" and "fourth". XSD validators don't seem to like the idea of the same element defined with two different rulesets.

How do I construct an XML schema document to enforce this rule?

+1  A: 

Unfortunately you can't do this with XDS, see schema component constraint cos-element-consistent. You can either change the content model as a workaround or use e.g. Relax NG that will allow this.

jelovirt