XML Schema choice element
Definition and usage
The XML Schema choice element allows only one of the elements contained in the <choice> declaration to appear in the containing element.
Element information
Occurrence times | Once in the group and complexType elements; unrestricted otherwise. |
Parent element | group, choice, sequence, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent) |
Content | annotation, any, choice, element, group, sequence |
Syntax
<choice id=ID maxOccurs=nonNegativeInteger|unbounded minOccurs=nonNegativeInteger any attributes > (annotation?,(element|group|choice|sequence|any)*) </choice>
(The ? symbol declares that the element can appear zero or once in the choice element, and the * symbol declares that the element can appear zero or multiple times.)
Attributes | Description |
---|---|
id | Optional. Specifies the unique ID of the element. |
maxOccurs | Optional. Specifies the maximum number of times the choice element can appear in the parent element. This value can be an integer greater than or equal to zero. If you do not want to set any limit on the maximum number, use the string "unbounded". The default value is 1. |
minOccurs | Optional. Specifies the minimum number of times the choice element can appear in the parent element. This value can be an integer greater than or equal to zero. To specify that this any group is optional, set this attribute to zero. The default value is 1. |
any attributes | Optional. Definiert jede andere Eigenschaft mit non-schema Namensraum. |
Beispiel
<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>
Der obige Beispiel definiert, dass das "person"-Element ein "employee"-Element oder ein "member"-Element enthalten muss.