The xsd:choice type is converted to an ASN.1 CHOICE type. ASN1C generates exactly the same code. For example:
<xsd:complexType name="NamePart">
<xsd:choice>
<xsd:element name="givenName" type="xsd:string "/>
<xsd:element name="initial" type="xsd:string"/>
<xsd:element name="familyName" type="xsd:string"/>
</xsd:choice>
</xsd:complexType>
in this case, the generated code is the same as for ASN.1 CHOICE:
#define T_NamePart_givenName 1
#define T_NamePart_initial 2
#define T_NamePart_familyName 3
typedef struct EXTERN NamePart {
int t;
union {
/* t = 1 */
const OSUTF8CHAR* givenName;
/* t = 2 */
const OSUTF8CHAR* initial;
/* t = 3 */
const OSUTF8CHAR* familyName;
} u;
} NamePart;
Similar to xsd:choice is xsd:union. The main difference is that xsd:union alternatives are unnamed. As specified in X.694, special names are generated in this case using the base name “alt”. The generated name for the first member is “alt”; names for successive members are “alt-n” where n is a sequential number starting at 1. An example of this naming is as follows:
<xsd:simpleType name="MyType">
<xsd:union memberTypes="xsd:int xsd:language"/>
</xsd:simpleType>
This generates the following C type definition:
#define T_MyType_alt 1
#define T_MyType_alt_1 2
typedef struct EXTERN MyType {
int t;
union {
/* t = 1 */
OSINT32 alt;
/* t = 2 */
const OSUTF8CHAR* alt_1;
} u;
} MyType;