XML Schema sequence 元素

定義和用法
sequence 元素要求組中的元素以指定的順序出現在包含元素中。每個子元素可出現 0 次到任意次數。
元素資訊
- 父元素: group, choice, sequence, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
語法
<sequence
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</sequence>
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</sequence>
(? 聲明在 sequence 元素中該元素可出現零次或一次。)
屬性 | 描述 |
---|---|
id | 可選。規定該元素的唯一的 ID。 |
maxOccurs | 可選。規定 any 元素在父元素中可出現的最大次數。該值可以是大於或等於零的整數。若不想對最大次數設置任何限制,請使用字串 "unbounded"。 默認值為 1。 |
minOccurs | 可選。規定 any 元素在父元素中可出現的最小次數。該值可以是大於或等於零的整數。若要指定該 any 組是可選的,請將此屬性設置為零。 默認值為 1。 |
any attributes | 可選。規定帶有 non-schema 命名空間的任何其他屬性。 |
實例 1
本例是一個針對 "personinfo" 元素的聲明,該元素必需按順序包含下列 5 個元素:"firstname", "lastname", "address", "city", and "country"。
<xs:element name="personinfo">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
實例 2
本例是一個針對 "pets" 元素的聲明,可包含零個或多個 dog 和 cat 元素:
<xs:element name="pets">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="dog" type="xs:string"/>
<xs:element name="cat" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="dog" type="xs:string"/>
<xs:element name="cat" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
