選択したグループに含まれている要素のうちの 1 つだけをコンテナ要素内に含めることができます。
<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
指定できる choice の最大出現回数。値は 0 以上の整数です。最大数で上限を設定しない場合は、文字列 "unbounded" を使用します。既定値は 1 です。省略可能です。
minOccurs
指定できる choice の最小出現回数。値は 0 以上の整数です。この choice グループが省略可能であることを指定するには、この属性を zero に設定します。既定値は 1 です。省略可能です。
要素情報
出現回数 | group 要素および complexType 要素内では 1 回、それ以外は無制限。 |
親要素 | group、choice、sequence、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent) |
コンテンツ | annotation、any、choice、element、group、sequence |
例
1 つの属性を持ち、指定した 4 つの要素のうちの 1 つの要素だけを含む要素を定義する複合型の例を次に示します。
<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>
参照
XML スキーマ リファレンス (XSD) | XML スキーマの要素
詳細については、http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-choice で、W3C『XML Schema Part 1: Structures Recommendation』を参照してください。