Versions Compared

Key

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

...

The child nodes of a Repeat Node may repeat 0, 1, or more times. In addition to common attributes Repeat Nodes may have the following attributes:

...

Sequence Nodes simply define a collection of child nodes. These can be used to define a set of child nodes as a template; or to define the start and end of a sequence of Attribute Nodes that have an overall length specified by another Attribute Node (for example, a Length Node somewhere within the same node hierarchy.
In addition to common attributes  Sequence Nodes may have the following attributes:

...

See Attribute Node for details of discriminators. A Choice Node has no attributes other than the common attributes.

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"/>

...

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:

Solution 1

Add an additional Attribute Node to the Choice Node with a discriminator of 3, as below:

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="type2" discriminator="2" type="String"/>
    <Attr name="stringValue" bytes="8" type="String"/>
  </Sequence>
  <Attr name="type3" discriminator="3" type="String/>
</Choice>
<Attr name="final" bytes="2" type="Integer"/>

Solution 2

Add an Attribute Node to the Choice Node to pick up any value that is not 1 or 2, as below:

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="type2" discriminator="2" type="String"/>
    <Attr name="stringValue" bytes="8" type="String"/>
  </Sequence>
  <Attr name="type3" bytes="1" type="String/>
</Choice>
<Attr name="final" bytes="2" type="Integer"/>

Solution 3

Note that in the snippet above, if no discriminator is set on the Attribute Node type3 then the number of bytes or bits must be set. You cannot have more than one generic option like this in a Choice Node, since this will make the grammar ambiguous.

...