<xsd:choice> 元素

允许且仅允许选定组中包含的一个元素出现在包含元素中。

<choice
  id = ID 
  maxOccurs= (nonNegativeInteger | unbounded) : 1
  minOccurs= nonNegativeInteger : 1 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>

属性

  • id
    该元素的 ID。 id 值必须属于类型 ID 并且在包含该元素的文档中是唯一的。

    可选项。

  • maxOccurs
    可进行选择的最大次数。 该值可以是大于或等于零的整数。 若不想对最大次数设置任何限制,请使用字符串“unbounded”。 默认值为 1。

    可选项。

  • minOccurs
    可进行选择的最小次数。 该值可以是大于或等于零的整数。 若要指定该选项组是可选的,请将此属性设置为 zero。 默认值为 1。

    可选项。

元素信息

出现次数

groupcomplexType 元素中为一次;其他为无限制。

父元素

groupchoicesequencecomplexTyperestriction (simpleContent)extension (simpleContent)restriction (complexContent)extension (complexContent)

内容

annotationanychoiceelementgroupsequence

示例

以下复杂类型定义一个元素,该元素具有一个属性,并且有一个且仅有一个元素来自四个指定元素的选择。

<xs:complexType name="chadState">
 <xs:choice minOccurs="1" maxOccurs="1">
  <xs:element ref="selected"/>
  <xs:element ref="unselected"/>
  <xs:element ref="dimpled"/>
  <xs:element ref="perforated"/>
 </xs:choice>
 <xs:attribute name="candidate" type="candidateType"/>
</xs:complexType>

其他资源

有关更多信息,请参见“W3C XML Schema Part 1: Structures Recommendation”(W3C XML 架构第 1 部分:结构建议),网址为 www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all。

另请参见

参考

XML 架构 (XSD) 参考
XML 架构元素