XSD:如何创建可以按任何顺序排列的元素,可选,但不能出现多次

时间:2016-11-19 19:29:48

标签: xml xsd xsd-validation xml-validation

正如标题所述。 我遇到麻烦的主要部分是使元素不会出现多次。出于某种原因,我无法弄明白。我认为min和max会解决问题。

以下是元素的规范,下面是我到目前为止的代码。

 <!--
        13.1. The element info has an optional updated element. If present, appears exactly once.
        Represents the last day and time the feed was updated on your company’s servers.
        13.2. The element info has an optional copyright element. If present, appears exactly once.
        Represents the copyright holder of the feed data.
        13.3. The element info has an optional location element. If present, appears exactly once.
        Represents the physical location of the company with the feed.
            13.3.1. These three elements can appear in any order, and all three are optional.
    -->
    <xs:element name="info" >
        <xs:complexType mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="target:updated" minOccurs="0" maxOccurs="1" />
            <xs:element ref="target:copyright" minOccurs="0" maxOccurs="1" />
            <xs:element ref="target:location" minOccurs="0" maxOccurs="1" />
          </xs:choice>
        </xs:complexType>
    </xs:element>

1 个答案:

答案 0 :(得分:2)

XSD 1.0 中,使用 xs:all 元素。

<xs:element name="info" >
    <xs:complexType mixed="true">
        <xs:all>
            <xs:element ref="target:updated" minOccurs="0" maxOccurs="1" />
            <xs:element ref="target:copyright" minOccurs="0" maxOccurs="1" />
            <xs:element ref="target:location" minOccurs="0" maxOccurs="1" />
        </xs:all>
    </xs:complexType>
</xs:element>