views:

22

answers:

2

I have some XSD that looks something like this:

<element name="a">
  <complexType>
    <sequence>
      <element name="b" type="t:typ" minOccurs="1" maxOccurs="unbounded" />
      <element name="c" type="t:typ" minOccurs="1" maxOccurs="unbounded" />
    </sequence>
  </complexType>
</element>

How would I change it so that instead of a sequence, I could allow the tags b and c to be jumbled in any order, e.g. how would I make this valid?..

<a>
  <b />
  <c />
  <b />
  <c />
  <b />
  <b />
</a>

The 'all' option sounded promising, but it seems to only allow no more than one of each of the child elements.

+3  A: 

I believe you want this:

<element name="a">
  <complexType>
    <choice maxOccurs="unbounded">
      <element name="b" type="t:typ" />
      <element name="c" type="t:typ" />
    </choice>
  </complexType>
</element>
Dennis Palmer
interesting approach! I was thinking it wouldn't work, since <xs:choice> only allows one of its child elements - but the maxOccurs=unbounded on the <xs:choice> probably does the trick!
marc_s
Seems to work, thanks :) Next problem would be to try to restrict one of the choices to one instance only... Another question, methinks.
izb
A: 

Could you try an unbounded sequence of choice elements? Something like this? (untested)

<element name="a"> 
  <complexType> 
    <sequence maxOccurs="unbounded" minOccurs="0">
      <choice> 
        <element name="b" type="t:typ" /> 
        <element name="c" type="t:typ" /> 
      </choice>
    </sequence>
  </complexType> 
</element> 
Simon Nickerson