My preference is the latter. I think expressions for delimiters should be 
avoided if possible.

One may get better diagnostics here if in fact what is found in the data stream 
is neither a "(" nor "[".


But, if you had a larger number of branch cases, one could argue in favor of 
the expression for performance reasons.

________________________________
From: Costello, Roger L. <[email protected]>
Sent: Monday, June 3, 2019 9:07:21 AM
To: [email protected]
Subject: Best Practice: dynamically compute initiator/terminator or choice with 
initiatedContent="yes"?


Hello DFDL community,



My input file has a number (num), followed by a comma-separated pair of values, 
enclosed within either round parentheses or square parentheses. If num=1 then 
the initiator and terminator are rounded parentheses. If num=2 then the 
initiator and terminator are square parentheses.



Below are two solutions to the problem. The first solution dynamically computes 
the initiator and terminator. The second solution uses a choice with 
dfdl:initiatedContent="yes".



Which solution is better?



Solution #1 Dynamically Compute initiator and terminator



<xs:element name="input">
    <xs:complexType>
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix">
            <xs:element name="num" type="xs:integer" />
            <xs:sequence dfdl:initiator="{if (num eq 1) then '(' else '[' }"
                dfdl:terminator="{if (num eq 1) then ')' else ']' }"
                dfdl:separator="," dfdl:separatorPosition="infix">
                <xs:element name="A" type="xs:string" />
                <xs:element name="B" type="xs:string" />
            </xs:sequence>
        </xs:sequence>
    </xs:complexType>
</xs:element>



Solution #2 Choice with initiatedContent="yes"



<xs:element name="input">
    <xs:complexType>
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="infix">
            <xs:element name="num" type="xs:integer" />
            <xs:choice dfdl:initiatedContent="yes">
                <xs:element name="A" type="xs:string" dfdl:initiator="(" 
dfdl:terminator=")" />
                <xs:element name="B" type="xs:string"  dfdl:initiator="[" 
dfdl:terminator="]" />
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>


Reply via email to