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

元素以任何顺序出现任意次数的xml模式构造,xml,schema,Xml,Schema,我想写一个xml模式,它可以接受一些元素,这些元素可以以任何顺序出现任意次数。比如下面的例子。它应该满足所有类似的组合。请帮助我,并提前表示感谢 例1 例2 像这样的方法应该会奏效: <?xml version="1.0" encoding="utf-8"?> <xs:schema id="root" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <

我想写一个xml模式,它可以接受一些元素,这些元素可以以任何顺序出现任意次数。比如下面的例子。它应该满足所有类似的组合。请帮助我,并提前表示感谢

例1 例2
像这样的方法应该会奏效:

<?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>
基本上,为您提供了选择任意一个包含的节点的选项,例如,或中的任意一个。有关各种选项的更多说明,请参阅

由于属性minOccurs=0和maxOccurs=unbounded,因此可以重复拾取任何包含的节点场景任意次数


最后,你可以选择任意数量的节点,每次你都可以选择节点1或节点2或更多,如果你给

marc_s的答案一针见血的话


当我编写模式时,我发现这个资源非常有用:

非常感谢marc_,它帮助我克服了我的问题。。。再次感谢……啊,废话。我想我错过了你们学校的链接,最后发布了一个重复的答案。嘿,如果你能更改已接受的答案,请将其切换到marc_s。@Merlyn Morgan Graham:我感谢你的诚实:-无论如何,谢谢你的努力:-
<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>