XML Schema choice 元素

定义和用法

XML Schema 的 choice 元素仅允许包含在 <choice> 声明中的元素之一出现在包含元素中。

元素信息

出现次数 在 group 和 complexType 元素中为一次;其他为无限制。
父元素 group、choice、sequence、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent)
内容 annotation、any、choice、element、group、sequence

语法

<choice
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
任意属性
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>

(? 符号声明在 choice 元素中,元素可出现零次或一次,* 符号声明元素可出现零次或多次。)

属性 描述
id 任意。指定该元素的唯一 ID。
maxOccurs 任意。指定 choice 元素在父元素中可出现的最大次数。此值可以是大于或等于零的整数。若不想对最大次数设置任何限制,请使用字符串 "unbounded"。默认值为 1。
minOccurs 任意。指定 choice 元素在父元素中可出现的最小次数。此值可以是大于或等于零的整数。若要指定此任意组是可选的,请将此属性设置为 0。默认值为 1。
任意属性 任意。指定带有 non-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" 要素を含む必要があります。