dirtside
dirtside

Reputation: 8270

Same element, multiple types with XML Schema

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?

Upvotes: 0

Views: 2304

Answers (1)

jelovirt
jelovirt

Reputation: 5892

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.

Upvotes: 1

Related Questions