Unions are encoded as a xs:complexType containing a xs:sequence with two entries.

The first entry in the sequence is the SwitchField xs:element and specifies a numeric value which identifies which element in the xs:choice is encoded. The name of element may be any valid text.

The second entry in the sequence is an xs:choice which specifies the possible fields. The order in the xs:choice determines the value of the SwitchField when that choice is encoded. The first element has a SwitchField value of 1 and the last value has a SwitchField equal to the number of choices.

No additional elements in the sequence are permitted. If the SwitchField is missing or 0 then the union has a NULL value. Encoders or decoders shall report an error for any SwitchField value greater than the number of defined union fields.

For example, the following union has two fields. The XML schema would look like:

<xs:complexType name="Type1">


<xs:element name="SwitchField"

type="xs:unsignedInt" minOccurs="0"/>


<xs:element name="Field1" type="xs:int" minOccurs="0"/>

<xs:element name="Field2" type="tns:Field2" minOccurs="0"/> </xs:choice>