开发者

How can I have sub-elements of a complex/mixed type with unrestricted order and count?

开发者 https://www.devze.com 2022-12-29 21:16 出处:网络
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 po

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 开发者_如何学C<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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消