Data Format Description Language (DFDL) v1.0 Specification
OGF Proposed Recommendation GFD-P-R.174, January 31, 2011
A choice corresponds to concepts called variant records, multi-format records, discriminated unions, or tagged unions in various programming languages. In some contexts choices are referred to generally as 'unions'. However, this should not be confused with XML schema unions.
When processing a choice, speculative parsing is used. Processing works as follows:
Attempt to parse the first branch of the choice.
If this fails with a processing error
If we have evaluated a dfdl:discriminator to true earlier on this branch then the parser is 'bound' to this choice and parsing of the entire choice construct fails with a processing error.
If we have not evaluated a dfdl:discriminator to true then we repeat from step 1 for the next branch of the choice.
It is a processing error if we exhaust the branches of the choice
If we succeed to parse a branch without error, then that branch’s value becomes the logical value for the parse of the choice construct.
It is not possible for variable settings to be communicated from the speculative attempt to parse a branch to any other parsing situation. The speculative effort is completely isolated. Whether it succeeds or fails, neither the parse position in the source data, nor anything in the variable memory, nor the infoset is affected.
Nested choices can require unbounded look ahead into the data.
On unparsing the choice branch supplied in the infoset is output. It is a processing error is more than one choice branch is supplied. If no choice branch is supplied in the infoset then each choice branch is tried in schema definition order until one does not result in a processing error. It is a processing error if none of the choice branches unparse successfully.
Copyright (C) Open Grid Forum (2005-2010). All Rights Reserved.
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the OGF or other organizations, except as needed for the purpose of developing Grid Recommendations in which case the procedures for copyrights defined in the OGF Document process must be followed, or as required to translate it into languages other than English.