Structures with optional fields are encoded as a xs:complexType with all of the fields appearing in a sequence. The first element is a bit mask that specifies what fields are encoded. The bits in the mask are sequentially assigned to optional fields in the order they appear in the Structure.
To allow for compact XML, any field can be omitted from the XML so decoders shall assign DefaultValues based on the field type for any mandatory fields.
The xs: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 Structure has one mandatory and two optional fields. The XML schema would look like:
<xs:complexType name="OptionalType">
<xs:sequence>
<xs:element name="EncodingMask" type="xs:unsignedLong" />
<xs:element name="X" type="xs:int" minOccurs="0" />
<xs:element name="O1" type="xs:int" minOccurs="0" />
<xs:element name="Y" type="xs:byte" minOccurs="0" />
<xs:element name="O2" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
In the example above, the EncodingMask has a value of 3 if both O1 and O2 are encoded. Encoders shall set unused bits to 0 and decoders shall ignore unused bits.
If a Structure with optional fields is subtyped, the subtypes extend the EncodingMask defined for the parent.