当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XML Schema choice 元素
XML Schema choice element allows only one of the elements contained in the <choice> declaration to be present within the containing element.
XML Schema choice 元素允许使用通过<choice>声明的嵌套元素中一个元素。
<choice id=ID maxOccurs=nonNegativeInteger|unbounded minOccurs=nonNegativeInteger any attributes > (annotation?,(element|group|choice|sequence|any)*) </choice> |
(The ? sign declares that the element can occur zero or one time, and the * sign declares that the element can occur zero or more times inside the choice element)
“?”符号用于声明元素可以出现的次数(0次或1次),“*”符号用于声明元素可以在choice元素中出现的次数(0次或多次)。
属性 | 描述 |
---|---|
id | Optional. Specifies a unique ID for the element 可选参数。为元素指定一个独立的ID |
maxOccurs | Optional. Specifies the maximum number of times the choice element can occur in the parent element. The value can be any number >= 0, or if you want to set no limit on the maximum number, use the value "unbounded". Default value is 1 可选参数。指定choice元素在父类元素中出现的最大次数。其值可以大于等于0;或者,如果你不希望对最大值进行限制,可以使用“unbounded”。默认值是1 |
minOccurs | Optional. Specifies the minimum number of times the choice element can occur in the parent the element. The value can be any number >= 0. Default value is 1 可选参数。指定choice元素在父类元素中出现的最小次数。其值可以大于等于0。默认值是1 |
any attributes | Optional. Specifies any other attributes with non-schema namespace 可选参数。指定非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> |
The example above defines an element named "person" which must contain either a "employee" element or a "member" element.
上述案例定义了一个名为“person”的元素,它必须包含一个“employee”元素或一个“member”元素。