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 参考