元素以任何顺序出现任意次数的 xml 架构构造 [英] xml schema construct for elements to occur any number of times in any order

查看:34
本文介绍了元素以任何顺序出现任意次数的 xml 架构构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 xml 模式,它可以接受一些可以以任何顺序出现任意次数的元素.像下面的例子.它应该满足所有相似的组合.租赁帮助我并提前致谢.

i wanna write an xml schema that can accept some elements that can occur any number of times in any order. like following examples. it should satisfy all similar combination. lease help me and thanks in advance.

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

基本上, 为您提供了选择任何一个包含节点的选项,例如 中的任何一个.有关各种选项的更多说明,请参阅 W3Schools 的文章.

Basically, the <xs:choice> gives you the option to pick any one of the contained nodes, e.g. any one of <node1> or <node2>. See W3Schools' article for more explanations about the various options.

由于 具有属性 minOccurs="0"maxOccurs="unbounded",您可以重复选择任何包含的节点"场景任意次数.

Since the <xs:choice> has attributes minOccurs="0" and maxOccurs="unbounded", you can repeat that "pick any of the contained nodes" scenario any number of times.

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

In the end, you can pick any number of nodes, and each time, you can pick either node1 or node2 (or more, if you add more options to the <xs:choice>)

这篇关于元素以任何顺序出现任意次数的 xml 架构构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆