Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A Choice Node specifies that only one or zero of its child nodes (with all its descendant nodes) may be present in the file. Each child node is therefore optional, and setting the optional attribute to F will have no effect. 

For the binary file reader to determine which of the child nodes under a Choice Node are in a file, the discriminator attribute must be set on:

  • the child node itself, or
  • the first child Attribute or Record Node of the child node.

See 3.4.2Attribute Node for details of discriminators. A Choice Node has no attributes other than the common attributes (see 3.1).
<Choice>
<Sequence .

Code Block
languagexml
<Choice>
  <Sequence name="option1">

...


    <Attr name="type1" discriminator="1" type="String"/>

...


    <Attr name="numberValue" bytes="2" type="Integer"/>

...


  </Sequence>

...


  <Sequence name="option2">

...


    <Attr name="type" discriminator="2" type="String"/>

...


    <Attr name="stringValue" bytes="8" type="String"/>

...


  </Sequence>

...


</Choice>

...


<Attr name="final" bytes="2" type="Integer"/>


In the snippet above, if the first byte encountered is 1 then the next section of the file will be recognised as a Sequence Node option1, the next 2 bytes will be interpreted as a number, before moving on to the Attribute Node final.

If the first byte encountered is 2 then the next section of the file will be recognised as a Sequence Node option2, the next 8 bytes will be interpreted as a string, before moving on to the Attribute Node final.

If the first byte encountered is a 3 then the reader will fail with an error since the snippet only handles 1 or 2 in the first byte. If a 3 is a valid possibility there are three possible solutions:

...