通过 XSD 允许 XML 元素以任意顺序出现任意数量?

Allow XML element in any order with any number of appearance via XSD?

我在写 XSD 时遇到了困难:需要 Name 元素; Value 元素可以出现 0 次或多次; 类别 元素是可选的。我现在 XSD 是这样的:

<xs:element name="Detail" maxOccurs="unbounded" minOccurs="0"> <!-- 0 or more Details -->
  <xs:complexType>
    <xs:sequence>
      <xs:element type="xs:string" name="Name"/> <!-- Name element is required -->
      <xs:element type="xs:string" name="Value" maxOccurs="unbounded" minOccurs="0"/> <!-- 0 or more occurences of Value element -->
      <xs:element type="xs:string" name="Category" minOccurs="0" maxOccurs="1"/> <!-- optional (0 or 1) Category element -->
    </xs:sequence>
  </xs:complexType>
</xs:element>

问题是输入 XML 可能不符合架构中的顺序。 xs:choicexs:all 的外观约束对我来说不够好。

谁能帮我解决这个允许 XML 元素以任意顺序出现任意次数的问题?

附加示例输入 XML:

<Detail>
    <Category />
    <Name> Thanks </Name>
    <Value> 1 </Value>
    <Value> 2 </Value>
</Detail>

XSD1.0

不可能。要么强加一个顺序,要么放宽出现限制。

XSD1.1

可能,因为在 XSD 1.1 中,xs:all 的 children 现在可能有 @maxOccurs="unbounded"

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
           elementFormDefault="qualified"
  vc:minVersion="1.1">
  <xs:element name="Detail"> 
    <xs:complexType>
      <xs:all>
        <xs:element type="xs:string" name="Name"/>
        <xs:element type="xs:string" name="Value" 
                    minOccurs="0" maxOccurs="unbounded" />
        <xs:element type="xs:string" name="Category" 
                    minOccurs="0" maxOccurs="1"/>
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>