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. The compiler indexes all elements of a record with an XMLChoice attribute but the Genero Web Server (GWS) only serializes the element set by the selector value as the member to be serialized. If the selected element has no XMLName attribute, it will use the Genero BDL name as the XML tag.
  2. Nested choice records cannot be defined as main variables; there must always be a surrounding variable.

Example: Record with XMLChoice

In the sample record, note the index value of the record element shown in the comment with the hash symbol ( # ).

DEFINE mychoice RECORD ATTRIBUTES(XMLChoice,XMLName="Root")
  val1  INTEGER   ATTRIBUTES(XMLName="Val1"),              #1 
  val2  FLOAT     ATTRIBUTES(XMLAttribute,XMLName="Val2"), #2 
  sel   SMALLINT  ATTRIBUTES(XMLSelector),                 #3 selector node
  val3  STRING    ATTRIBUTES(XMLName="Val3")               #4 
END RECORD

Case where "sel" value is set to 4 (LET mychoice.sel = 4). The XML output is:

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

Case where "sel" value is set to 1 (LET mychoice.sel = 1). The XML output is:

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

Example: Record with nested XMLChoice record

In the example, note the index value of the nested record elements shown in the comment with the hash symbol ( # ).
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"),    #1 
    choice2   FLOAT     ATTRIBUTES(XMLName="ChoiceTwo"),    #2 
    nestedSel SMALLINT  ATTRIBUTES(XMLSelector)             #3 selector node
  END RECORD,
  val3  STRING    ATTRIBUTES(XMLName="Val3")
END RECORD
Case where "nestedSel" value is set to 1 (LET myVar.choice.nestedSel = 1). The XML output is:
<Root Val2="25.8">
  <Val1>148</Val1>
  <ChoiceOne>6584</ChoiceOne>
  <Val3>Hello world</Val3>
</Root>
Case where "nestedSel" value is set to 2 (LET myVar.choice.nestedSel = 2). The XML output is:
<Root Val2="25.8">
  <Val1>148</Val1>
  <ChoiceTwo>85.8</ChoiceTwo>
  <Val3>Hello world</Val3>
</Root>