CHOICE

The ASN.1 CHOICE type is used to specify a list of alternative elements from which a single element can be selected. This type is mapped to the XSD choice complex type. The mapping is as follows:

ASN.1 production:

   TypeName ::= CHOICE {
      element1-name element1-type,
      element2-name element2-type,
      ...
   } 

Generated XSD code:

   <xsd:complexType name="TypeName">
      <xsd:choice>
         <xsd:element name="element1-name" type="element1-type"/>
         <xsd:element name="element2-name" type="element2-name"/>
         ...
      </xsd:choice>
   </xsd:complexType>typedef struct {

This is similar to the SEQUENCE and SET cases described above. The only difference is that xsd:choice is used instead of xsd:sequence or xsd:all.

The CHOICE type cannot have elements marked as optional (OPTIONAL) or elements that contain default values (DEFAULT) as was the case for SEQUENCE and SET.

If the CHOICE type is extensible (i.e., contains an ellipses marker ...), a special element will be inserted to allow an unknown alternative to be validated. This element is as follows:

   <xsd:any namespace="##other" processContents="lax"/>

This element declaration allows any additional elements from other namespaces to exist in a message instance without causing a validation or decoding error. Note the restriction that the element must be defined in a different namespace. This is necessary because if the element existed in the same namespace as other elements, the content model would be non-deterministic. The reason is because a validation program would not be able to determine if the choice alternative element is a defined element or an extension element.