XMLChoice

Map a BDL Record to an XML Schema choice structure. The choice of the record's member is performed at runtime, and changes dynamically depending on a mandatory member. This specific member must be of type SMALLINT or INTEGER, and have an XMLSelector attribute set. The XMLChoice attribute also supports a "nested" value that removes the surrounding XML tag.

Note:
  1. Valid selector values are indexes referring to members considered as XML element nodes. All other values will raise XML runtime errors.
  2. Nested choice records cannot be defined as main variables; there must always be a surrounding variable.

Example

DEFINE mychoice RECORD ATTRIBUTES(XMLChoice,XMLName="Root")
  val1  INTEGER   ATTRIBUTES(XMLName="Val1"),
  val2  FLOAT     ATTRIBUTES(XMLAttribute,XMLName="Val2"),
  sel   SMALLINT  ATTRIBUTES(XMLSelector),
  val3  STRING    ATTRIBUTES(XMLName="Val3")
END RECORD

Case where "sel" value is 4

<Root Val2="25.8">
  <Val3>Hello world</Val3>
</Root>

Case where "sel" value is 1

<Root Val2="25.8">
  <Val1>148</Val1>
</Root>

Nested example:

DEFINE myVar RECORD ATTRIBUTES(XMLName="Root")
  val1  INTEGER   ATTRIBUTES(XMLName="Val1"),
  val2  FLOAT     ATTRIBUTES(XMLAttribute,XMLName="Val2"),
  choice RECORD   ATTRIBUTES(XMLChoice="nested")
    choice1   INTEGER   ATTRIBUTES(XMLName="ChoiceOne"),
    choice2   FLOAT     ATTRIBUTES(XMLName="ChoiceTwo"),
    nestedSel SMALLINT  ATTRIBUTES(XMLSelector)
  END RECORD,
  val3  STRING    ATTRIBUTES(XMLName="Val3")
END RECORD

Case where "nestedSel" value is 1

<Root Val2="25.8">
  <Val1>148</Val1>
  <ChoiceOne>6584</ChoiceOne>
  <Val3>Hello world</Val3>
</Root>

Case where "nestedSel" value is 2

<Root Val2="25.8">
  <Val1>148</Val1>
  <ChoiceTwo>85.8</ChoiceTwo>
  <Val3>Hello world</Val3>
</Root>