[DFDL-WG] default case needed for choice-by-dispatch

Mike Beckerle mbeckerle at apache.org
Mon May 16 11:57:54 EDT 2022


I know this feature was discussed at one time.

The priority of this has gone up for us substantially, as the idiom in DFDL
v1.0 for a choice-by-dispatch to have a default case when the
choiceDispatchKey doesn't match any choiceBranchKey is far too complex.

This appears to be what is needed:

<!-- just a shorthand so we can discriminate true on one DFDL line -->
<group name="discriminateTrue">
        <sequence>
            <annontation><appinfo ...>
                 <dfdl:discriminator>{ fn:true() }</dfdl:discriminator>
            </appinfo></annotation>
        </sequence>
</group>

....
  <choice>
        <choice dfdl:choiceDispatchKey='{ ... dispatch key expr... }'>
            <sequence dfdl:choiceBranchKey="key1">
               <group ref="p:discriminateTrue"/>
                ... parse the key1 branch ....
            </sequence>
            ...
            <sequence dfdl:choiceBranchKey="keyN">
               <group ref="p:discriminateTrue"/>
                ... parse the keyN branch ....
            </sequence>
        </choice>
     <!-- default case below if the dispatch key does not match anything
-->
     <element name="invalidKey" ....>
       ...
     </element>
  </choice>
.....

The need for a discriminator for the outer choice on every single branch of
the inner choice is tedious at best. This is needed because if you don't
have this discriminator, then the backtrack will choose the other choice
alternative for any failure of a branch, not just no branch key match, and
one will get a diagnostic that the branch key was not found when it was
found but the subsequent parse failed.

This structure is too complex for DFDL schema authors to get right. A way
to specify an additional choice branch which is the default to be used on
no-match to the other branch keys, is needed.

An explicit dfdlx:choiceBranchDefault="yes" is one way to do this.

A final choice branch with no dfdl:choiceBranchKey would also work but
seems too error-prone for my taste. A default case should be explicitly
marked as such, even if we require it to be the last branch.




Mike Beckerle
Apache Daffodil PMC | daffodil.apache.org
OGF DFDL Workgroup Co-Chair | www.ogf.org/ogf/doku.php/standards/dfdl/dfdl
Owl Cyber Defense | www.owlcyberdefense.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ogf.org/pipermail/dfdl-wg/attachments/20220516/ffc56aeb/attachment.html>


More information about the dfdl-wg mailing list