XSD:如何创建可以任意顺序,可选,但不能出现多次的元素
XSD: How to create elements that can be in any order, optional, but cannot appear more than once
如标题所述。
我遇到麻烦的主要部分是使元素不出现多次。出于某种原因,我无法弄清楚。我认为出现最小值和最大值会解决问题。
这是元素的规格,下面是我目前的代码。
<!--
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>
在XSD1.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>
如标题所述。 我遇到麻烦的主要部分是使元素不出现多次。出于某种原因,我无法弄清楚。我认为出现最小值和最大值会解决问题。
这是元素的规格,下面是我目前的代码。
<!--
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>
在XSD1.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>