You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "Steve Lawrence (Jira)" <ji...@apache.org> on 2023/01/24 14:50:00 UTC
[jira] [Commented] (DAFFODIL-2231) Separator unparsed even when dfdl:occursCount expression is zero
[ https://issues.apache.org/jira/browse/DAFFODIL-2231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17680241#comment-17680241 ]
Steve Lawrence commented on DAFFODIL-2231:
------------------------------------------
Found some old emails where this was referenced and as able to create a minimal example:
The schema:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
xmlns:ex="https://example.com"
targetNamespace="https://example.com">
<include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
<annotation>
<appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format xmlns="" ref="GeneralFormat"
lengthKind="delimited" />
<dfdl:defineVariable name="hasField" type="xs:boolean" external="true">false</dfdl:defineVariable>
</appinfo>
</annotation>
<element name="root" dfdl:terminator="%NL;">
<complexType>
<sequence dfdl:separator="|">
<element name="field1" type="xs:string" minOccurs="0"
dfdl:occursCountKind="expression"
dfdl:occursCount="{ if ($ex:hasField) then 1 else 0 }" />
<element name="field2" type="xs:string" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>
</schema>
{code}
If you parse this data:
{code:java}
field2a|field2b|field2c
{code}
Then you get this infoset:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<ex:root xmlns:ex="https://example.com">
<field2>field2a</field2>
<field2>field2b</field2>
<field2>field2c</field2>
</ex:root>
{code}
But if you unparse that infoset, then you get this data:
{code:java}
|field2a|field2b|field2c
{code}
Note that even though field1 does not exist, on unparse it still outputs a separator.
If you change occursCountKind to implicit for field1, then it does unparse as expected, so this seems to be related to this being an expression that evaluates to zero occurrences.
> Separator unparsed even when dfdl:occursCount expression is zero
> ----------------------------------------------------------------
>
> Key: DAFFODIL-2231
> URL: https://issues.apache.org/jira/browse/DAFFODIL-2231
> Project: Daffodil
> Issue Type: Bug
> Components: Unparsing
> Reporter: Steve Lawrence
> Assignee: Steve Lawrence
> Priority: Major
> Fix For: 3.5.0
>
>
> See the attached schema, and the following data
> {quote}
> Year,Make,Model,Description,Price
> 1997,Ford,E350,"ac, abs, moon",2999.99
> 1999,Chevy,Venture Extended Edition,,4900.00
> 1999,Chevy,Venture Extended Edition,Very Large,5000.00
> 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00
> {quote}
> If the 'header' variable is set to "none" then this schema correctly does not create a <header> element because occursCount evaluates to 0. However, on unparse even though there is no header element, Daffodil still creates a separator, causing an empty newline to be output as the first line.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)