You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "Mike Beckerle (Jira)" <ji...@apache.org> on 2023/06/14 19:18:00 UTC
[jira] [Commented] (DAFFODIL-2824) warning needed when all contents are optional inside an optional element and dfdl:emptyElementParsePolicy="treatAsEmpty"
[ https://issues.apache.org/jira/browse/DAFFODIL-2824?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17732705#comment-17732705 ]
Mike Beckerle commented on DAFFODIL-2824:
-----------------------------------------
[~olabusayo] please proofread the above description. I want to be sure this captures the issue we were looking at today.
> warning needed when all contents are optional inside an optional element and dfdl:emptyElementParsePolicy="treatAsEmpty"
> ------------------------------------------------------------------------------------------------------------------------
>
> Key: DAFFODIL-2824
> URL: https://issues.apache.org/jira/browse/DAFFODIL-2824
> Project: Daffodil
> Issue Type: Improvement
> Components: Middle "End"
> Affects Versions: 3.4.0
> Reporter: Mike Beckerle
> Priority: Major
>
> A common mistake is to have an optional element of complex type which is a sequence of all optional elements.
> This requires dfdl:emptyElementParsePolicy="treatAsAbsent", which is NOT the usual default in Daffodil.
> (It is the default in the IBM-portable formats, just not in the standard daffodil-only formats)
> Example: (assume context is delimited)
>
> {code:java}
> <sequence dfdl:separator="%WSP+">
> <element name="required1" type="w:zlString" dfdl:initiator="999"/>
> <element name="optParent" minOccurs="0">
> <complexType>
> <sequence>
> <element name="optChild1" minOccurs="0" dfdl:initiator="//" type="w:string3"/>
> <element name="optChild2" minOccurs="0" dfdl:initiator="[[" type="w:string3" dfdl:terminator="]]"/>
> </sequence>
> </complexType>
> </element>
> <element name="optional2" type="zlString" dfdl:initiator="opt2" minOccurs="0"/>
> </sequence>
> {code}
> In the example above, if the data is
>
> {noformat}
> 999
> opt2
> {noformat}
> We want the infoset to be
>
> {code:java}
> <required1/>
> <optional2/>
> {code}
> But it won't be. It will try to construct this infoset:
>
> {code:java}
> <required1/>
> <optParent/>
> {code}
>
> But you can see that the optParent is deemed present, because an empty element is perfectly allowed by this schema, and dfdl:emptyElementParsePolicy="treatAsEmpty".
> Even though none of its children are present. It will then expect another separator, and will fail because there isn't one.
> To fix this, one should set dfdl:emptyElementParsePolicy="treatAsAbsent", and that's what the warning message should suggest.
> A less attractive fix is to add an assertion at the end of the optParent element like this:
>
> {code:java}
> <element name="optParent" minOccurs="0">
> <complexType>
> <sequence>
> <element name="optChild1" minOccurs="0" dfdl:initiator="//" type="w:string3"/>
> <element name="optChild2" minOccurs="0" dfdl:initiator="[[" type="w:string3" dfdl:terminator="]]"/>
> <sequence>
> <annotation><appinfo soruce="http://www.ogf.org/dfdl/"/>
> <!--
> One of the above children must exist or the
> enclosing parent does not exist
> -->
> <dfdl:assert>{ fn:exists(optChild1) or fn:exists(optChild2) }</dfdl:assert>
> </appinfo></annotation>
> </sequence>
> </sequence>
> </complexType>
> </element>
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)