繁体   English   中英

元素的xml模式构造以任意顺序出现多次

[英]xml schema construct for elements to occur any number of times in any order

我想编写一个XML模式,该模式可以接受某些元素,这些元素可以按任意顺序出现多次。 像下面的例子。 它应该满足所有类似的组合。 租赁帮助我,在此先感谢。

例子1

<root>
    <node1> one   </node1>
    <node1> two   </node1>
    <node2> three </node2>
    <node1> four  </node1>
    <node2> five  </node2>
    <node2> six   </node2>
</root>

例子2

<root>    
    <node1> one  </node1>
    <node2> two   </node2>
    <node1> three </node1>
    <node2> four  </node2>
    <node2> five  </node2>
    <node1> six   </node1>
    <node1> seven </node1>
</root>

这样的事情应该起作用:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="root" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="node1" nillable="true">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="node2" nillable="true">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

基本上, <xs:choice>使您可以选择任何一个包含的节点,例如<node1><node2>任何一个。 有关各种选项的更多说明,请参见W3Schools的文章

由于<xs:choice>具有minOccurs="0"maxOccurs="unbounded"属性,因此您可以多次重复“选择任何包含的节点”方案。

最后,您可以选择任意数量的节点,并且每次都可以选择node1或node2(或者,如果您向<xs:choice>添加更多选项,则可以选择更多个节点)

marc_s的答案就在头上。

在编写模式时,我发现此资源非常有用: http : //www.w3schools.com/Schema/schema_elements_ref.asp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM