开发者

XML Schema to match the following ("all", with unbounded maxOccurs?)

Say I have an element, call it <A>. <A> can have children types of <B> and <C>. Now - here's the twist. Any number of <B> and <C> children can live in <A>, in any order.

For example:

<A>
  <C>
  <C>
  <B>
  <C>
 开发者_运维知识库 <B>
  <B>
  <C>
  ...
</A>

Is there a schema rule that fits this? Seems like "all" would work, if I could put maxOccurs="unbounded", but I guess that's not legal.


Answering my own question -- looks like trang (http://www.thaiopensource.com/relaxng/trang.html) gave me the anwer:

<xs:element name="A">
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:element ref="B"/>
      <xs:element ref="C"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

Very cool!


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root" type="root"/>
  <xs:complexType name="root">
    <xs:choice minOccurs="0">
      <xs:element name="a"/>
    </xs:choice>
  </xs:complexType>
</xs:schema>

This schema validates

<root>
</root>

But if you omit minOccurs="0" of <xs:choice>, it does not.

It validates

<root>
  <a/>
</root>

without minOccurs="0".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜