简体   繁体   English

无序模式中的XML模式显示元素

[英]XML Schema Display Elements in Unordered pattern

I have a Schema XSD File that has the elements listed in the Sequence . 我有一个Schema XSD文件,其中包含序列中列出的元素。 The problem is that Sequence forces the XML file to list the elements in the order . 问题是Sequence强制XML文件列出顺序中的元素。 Now, I want to use the choice tag. 现在,我想使用选择标记。 But according to the xml specification, choice allows only one of the elements contained in the declaration to be present within the containing element. 但是根据xml规范,choice只允许声明中包含的一个元素出现在contains元素中。 Also, I can't use All tag because I want the occurrence more than once . 另外,我不能使用All标签,因为我想要多次出现 But, I want to display all the A, B, C, D and E in the un-ordered pattern . 但是,我希望以无序模式显示所有A,B,C,D和E. Any suggestions? 有什么建议么?

Xml Schema File Xml架构文件

<xsd:complexType>
    <xsd:sequence>
        <xsd:element name="A" />
        <xsd:element name="B" />
        <xsd:element name="C" />
        <xsd:element name="D" />
        <xsd:element name="E" />
    </xsd:sequence>
</xsd:complexType>

XML File (I want these elements to be in any order) XML文件(我希望这些元素以任何顺序排列)

<a>a</a>
<b>b</b>
<c>c</c>
<d>d</d>
<e>e</e>

This XSD, 这个XSD,

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="r">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element name="A" />
        <xsd:element name="B" />
        <xsd:element name="C" />
        <xsd:element name="D" />
        <xsd:element name="E" />
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

will validate elements A through E as children of r in any order and in any number of occurrences. 将以任何顺序和任意数量的事件验证元素AE作为r子元素。

Explanation 说明

The occurrence constraints on the xsd:choice element allow the choice itself to be repeated the indicated number of times. xsd:choice元素的出现约束允许选择本身重复指定的次数。 So, you can make a choice between the child elements zero times and get an empty content model for r . 因此,您可以在子元素之间进行零次选择,并获得r的空内容模型。 For one time, you can choose any of the children. 有一次,你可以选择任何一个孩子。 For a second time, you can choose the same child you did the first time, or any other child. 您可以第二次选择您第一次做的同一个孩子或任何其他孩子。 As you can see, this continued operation allows any number of the children elements to appear in any order. 如您所见,此持续操作允许任意数量的子元素以任何顺序出现。

Examples 例子

All of the following XML documents would be valid against the above XSD: 以下所有XML文档对上述XSD都有效:

  • <r></r>
  • <r><A/><A/></r>
  • <r><A/><A/><A/></r>
  • <r><A/><B/><A/><C/><A/><D/><A/><E/><A/></r>
  • <r><E/><D/><C/><B/><A/></r>

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

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