XMLChoice

Map a 4GL Record to an XML Schema choice structure. The choice of the record's member is performed at runtime, and changes dynamically according to 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.
DEFINE mychoice RECORD ATTRIBUTE(XMLChoice,XMLName="Root")
  val1  INTEGER   ATTRIBUTE(XMLName="Val1"),
  val2  FLOAT     ATTRIBUTE(XMLAttribute,XMLName="Val2"),
  sel   SMALLINT  ATTRIBUTE(XMLSelector),
  val3  STRING    ATTRIBUTE(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 ATTRIBUTE(XMLName="Root")
  val1  INTEGER   ATTRIBUTE(XMLName="Val1"),
  val2  FLOAT     ATTRIBUTE(XMLAttribute,XMLName="Val2"),
  choice RECORD   ATTRIBUTE(XMLChoice="nested")
    choice1   INTEGER   ATTRIBUTE(XMLName="ChoiceOne"),
    choice2   FLOAT     ATTRIBUTE(XMLName="ChoiceTwo"),
    nestedSel SMALLINT  ATTRIBUTE(XMLSelector)
  END RECORD,
  val3  STRING    ATTRIBUTE(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>