Single occurrence or optional choice element
For a choice element that has a minOccurs of 1 or 0 and a maxOccurs of 1, HydraExpress generates an enumeration that lists the allowable choices. The class that contains the choices also contains an accessor to specify which choice is selected in a given object. The schema below illustrates a simple example:
 
<complexType name="userName">
<choice>
<element name="fullName" type="string" />
<element name="lastName" type="string" />
<element name="nickName" type="string" />
</choice>
</complexType>
The generated class will have the following enum definition and accessor method:
 
enum choice {choiceUnknown, FullNameChoice,
LastNameChoice,NickNameChoice};
choice getChoice();
The generated UserName class also contains accessors and mutators for the fullName, lastName, and nickName elements. An instance of the UserName class may contain all of the elements simultaneously.
The first time a choice is encountered for a type, HydraExpress uses the name choice to represent the choice. This provides a simple mapping for typical schemas that we have seen. If more than one choice appears in the same type definition, HydraExpress uses the name choice2. Subsequent choices increment the number at the end of the name.
NOTE: If an element exists named “choice”, HydraExpress renames the choice element to choiceElement1.
The marshal/unmarshal logic relies on the choice member of the class to determine which element should be set (on unmarshal) or written out (on marshal). Each time an element is set with a different value, if it belongs to a choice content model definition, the choice member will be automatically updated to reflect that the element last set is the one that should be written out. This can be manually overridden by the user by calling the mutator method directly.