views:

19

answers:

1

I am working with XML where some elements will contain text with additional markup. This is similar to this example at W3Schools. However, I need the markup tags to be able to appear in any order and possibly more than once.

To modify their example for illustration:

<letter>
  Dear Mr.<name>John Smith</name>.
  Your order <orderid>1032</orderid>
  will be shipped on <shipdate>2001-07-13</shipdate>.
  Thank you, <name>Bob Adams</name>
</letter>

None of the options presented by W3Schools (on the page following the linked example) allow this XML due to the second <name> element. Their explanation of the "indicators" and my testing are consistent.

<xs:sequence> - violates the element order

<xs:choice> - more than one kind of element is used.

<xs:all> - maxOccurs is restricted to "1".

This seems like it should be basic, after all, XHTML allows such things. How do I define my schema to allow this?

A: 

After more searching, I found [this][1] answer, which solved by problem. @jelovirt upvoted!

Essentially, combining sequence and choice indicators.

<xs:complexType name="textItem" mixed="true">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="tag_1" type="xs:string" />
    ...
    <xs:element name="tag_n" type="xs:string" />
  </xs:choice>
</xs:complexType>
mbmcavoy
The sequence is unnecessary, just add an unbounded choice directly into textItem.
xcut
Thanks, xcut!I was still a bit confused as to what was going on. But I get it now. I think my previous failed test I had the <choice> nut unbounded, and each element inside unbounded. So, I had to make the choice once, and could repeat the chosen element, but not mix 'n' match!
mbmcavoy