开发者

How to create XML schema allowing a node or a node wrapped by another one

I stuck into creating an XSD schema allowing only next sequence of elements:

<root>
    <node />
    <node />
    ...
<root>

or

<root>
    <wrapper>
        <node />
        ...
    </wrapper>
    <node />
    ...
    <wrapper>
        <node />
        ...
    </wrapper>
<root>

i.e. a number of node, some of them could be wrapped, and some - not.

Here's what I already have:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="node" minOccurs="0" maxOccurs="unbounded" type="NodeElement" />
      </xs:sequence>
      <xs:sequence>
        <xs:element name="node" minOccurs="0" maxOccurs="unbounded" type="WrapperElement" />
      </xs:sequence>
    </xs:complexType>
  </xs:e开发者_JS百科lement>
  <xs:complexType name="NodeElement" ></xs:complexType>
  <xs:complexType name="WrapperElement" ></xs:complexType>
</xs:schema>


Am I missing something or wouldn't just a simple <xs:choice> be suitable

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="root">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="wrapper" />
        <xs:element ref="node" />
      </xs:choice>
    </xs:complexType>
  </xs:element>

  <xs:element name="wrapper">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="node" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="node" type="xs:string" />

</xs:schema>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜