XML Schema choice 元素
完整 XML Schema 參考手冊
定義和用法
XML Schema 的 choice 元素僅允許包含在 聲明中的元素之一出現(xiàn)在包含元素中。
元素信息
- 父元素: group, choice, sequence, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
語法
<choice
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>
(? 符號聲明在 choice 元素中,元素可出現(xiàn)零次或一次,* 符號聲明元素可出現(xiàn)零次或多次。)
屬性 | 描述 |
id | 可選。規(guī)定該元素的唯一的 ID。 |
maxOccurs | 可選。規(guī)定 choice 元素在父元素中可出現(xiàn)的最大次數(shù)。該值可以是大于或等于零的整數(shù)。若不想對最大次數(shù)設(shè)置任何限制,請使用字符串 "unbounded"。 默認(rèn)值為 1。 |
minOccurs | 可選。規(guī)定 choice 元素在父元素中可出現(xiàn)的最小次數(shù)。該值可以是大于或等于零的整數(shù)。若要指定該 any 組是可選的,請將此屬性設(shè)置為零。 默認(rèn)值為 1。 |
any attributes | 可選。規(guī)定帶有 non-schema 命名空間的任何其他屬性。 |
實(shí)例 1
<xs:element name="person">
??<xs:complexType>
????<xs:choice>
??????<xs:element name="employee" type="employee"/>
??????<xs:element name="member" type="member"/>
????</xs:choice>
??</xs:complexType>
</xs:element>
上面的例子定義 "person" 元素必須包含一個(gè) "employee" 元素或一個(gè) "member" 元素。
完整 XML Schema 參考手冊
更多建議: