XML Schema choice 元素
❮ 完整的 XML Schema 參考
定義和用法
XML Schema 的 choice 元素允許在包含元素內只出現 <choice> 宣告中包含的元素中的一個。
元素資訊
- 父元素: group, choice, sequence, complexType, restriction (simpleContent 和 complexContent), extension (simpleContent 和 complexContent)
語法
<choice
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
任何屬性
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>
(? 符號表示元素在 choice 元素內可以出現零次或一次,* 符號表示元素在 choice 元素內可以出現零次或多次)
Attribute | 描述 |
---|---|
id | 可選。指定元素的唯一 ID |
maxOccurs | 可選。指定 choice 元素在父元素中可以出現的最多次數。該值可以是任何大於或等於 0 的數字,如果您想設定無限制,可以使用值 "unbounded"。預設值為 1 |
minOccurs | 可選。指定 choice 元素在父元素中可以出現的最少次數。該值可以是任何大於或等於 0 的數字。預設值為 1 |
任何屬性 | 可選。指定任何其他非 schema 名稱空間的屬性 |
示例
<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" 的元素,該元素必須包含 "employee" 元素或 "member" 元素中的一個。
❮ 完整的 XML Schema 參考