Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 允许元素的随机顺序—在XSD架构中,有些元素重复,有些元素不重复_Xml_Xsd - Fatal编程技术网

Xml 允许元素的随机顺序—在XSD架构中,有些元素重复,有些元素不重复

Xml 允许元素的随机顺序—在XSD架构中,有些元素重复,有些元素不重复,xml,xsd,Xml,Xsd,我正在尝试创建XSD,并尝试编写具有以下要求的定义: Allow child elements specified to appear only once, but one elements to appear multiple times Allow child elements to be in any order 例如: <parent> <child1/> <child2/> <child3/> <child3/> </

我正在尝试创建XSD,并尝试编写具有以下要求的定义:

Allow child elements specified to appear only once, but one elements to appear multiple times
Allow child elements to be in any order
例如:

<parent>
<child1/>
<child2/>
<child3/>
<child3/>
</parent>


child1和child2元素必须能够交换顺序,但不能重复。

这个简单的v1.0版XSD将需要一个
父级
,在任何数量的
child3
中,以任何顺序正好有一个
child1
和一个
child2

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="parent">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
        <xs:choice>
          <xs:sequence>
            <xs:element name="child1"/>
            <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="child2"/>
            <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
          <xs:sequence>
            <xs:element name="child2"/>
            <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="child1"/>
            <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

在XSD 1.0中,通常不可能这样做,除非像@kjhughes那样列出所有可能的排列,如果您有超过4个允许的元素子元素,这将变得不可管理

在XSD1.1中,您可以编写

<xs:all>
  <xs:element name="child1"/>
  <xs:element name="child2"/>
  <xs:element name="child3" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>

欢迎使用堆栈溢出!请出示你的问题。您应该至少包括您遇到问题的代码的大纲(但最好是a),然后我们可以尝试帮助解决特定问题。你也应该阅读。