Unions are encoded as an xs:complexType containing an 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 the 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.
The name attribute restricts the set of characters that are permitted. See 5.3.5 for instructions on how to handle invalid characters.
For example, the following union has two fields. The XML schema would look like:
<xs:complexType name="Type1"> <xs:sequence> <xs:element name="SwitchField" type="xs:unsignedInt" minOccurs="0"/> <xs:choice> <xs:element name="Field1" type="xs:int" minOccurs="0"/> <xs:element name="Field2" type="tns:Field2" minOccurs="0"/> </xs:choice> </xs:sequence> </xs:complexType>