I've taken a look at this and have traced the issue down to a logic bug in the Daffodil sequence code. Essentially, optional elements that are not maxOccurs > 1 were being treated as scalar elements when they should have been treated as repeating elements, as Daffodil treats all optional elements as potentially repeating.
I've created a ticket and have opened a pull request with the fix. Once the request is reviewed, the fix will be pushed up to the master repo. Ticket: https://issues.apache.org/jira/browse/DAFFODIL-2261 PR: https://github.com/apache/incubator-daffodil/pull/308 Josh Adams [https://avatars3.githubusercontent.com/u/47359?s=400&v=4]<https://github.com/apache/incubator-daffodil/pull/308> Fixed issue unparsing optional unordered elements by jadams-tresys · Pull Request #308 · apache/incubator-daffodil<https://github.com/apache/incubator-daffodil/pull/308> A user discovered an issue when the first element of an unordered sequence is optinal and does not have a maxOccurs > 1. There was a logic error that was resulting in the element being treated a... github.com ________________________________ From: Adams, Joshua <jad...@tresys.com> Sent: Monday, December 30, 2019 8:19 AM To: Roger Costello <coste...@mitre.org>; users@daffodil.apache.org <users@daffodil.apache.org> Subject: Re: Unparsing unordered sequences behaviour Hello Peter and Roger, Unordered sequence support is going to be part of the official 2.50 release for Daffodil and is available if you are pulling the latest code from the Daffodil repo. That being said, the behaviour that Peter is seeing indicates that there may be a bug in the implementation. It may be related to the bug that Mike Beckerle found when unparsing choices, which is how unordered sequences are handled behind the scenes. I'm going to take a look at this today and try to figure out what is going on. Josh Adams ________________________________ From: Costello, Roger L. <coste...@mitre.org> Sent: Monday, December 30, 2019 7:01 AM To: users@daffodil.apache.org <users@daffodil.apache.org> Subject: RE: Unparsing unordered sequences behaviour Hi Peter, This web page says that Daffodil does not currently support unordered sequences: https://daffodil.apache.org/unsupported/ /Roger -----Original Message----- From: Peter Kostouros <peter.kostou...@awta.com.au> Sent: Sunday, December 29, 2019 9:24 PM To: users@daffodil.apache.org Subject: [EXT] Unparsing unordered sequences behaviour Hi I hope someone can clarify the behaviour I am seeing with respect to unparsing unordered sequences whose elements in the info set (to be unparsed) are a subset of those defined in the schema. Basically the case I have is an element that contains an unordered sequence of subelements, where each subelement is optional. Parsing such an example results in a successful transformation, however, unparsing that output results in error. A snapshot of the tmdl xsd is shown below <element name="seq2"> <complexType> <sequence dfdl:sequenceKind="unordered"> <element name="x" type="xsd:string" dfdl:initiator="X:" dfdl:terminator="%NL;" /> <element name="y" type="xsd:string" dfdl:initiator="Y:" dfdl:terminator="%NL;" /> </sequence> </complexType> </element> Unparsing something like the following results in error <seq2> <y>y0</y> </seq2> I have attached a test case (modified from daffodil-test-ibm1/src/test/resources/test-suite/tresys-contributed/) that demonstrates this, see Test Case BE004-A. In the system I am working with the error is of the form "Expected element start event for {pug}D03_Record, but received element end event for {}D_Records." for a definition like the following, where the info set being unparsed contains XML entries for D01_Record and D02_Record elements: <!-- DETAILS --> <xs:element dfdl:lengthKind="implicit" name="D_Records" minOccurs="0"> <xs:complexType> <xs:sequence dfdl:sequenceKind="unordered"> <xs:element ref="D01_Record" /> <xs:element ref="D02_Record" /> <xs:element ref="D03_Record" /> <xs:element ref="D04_Record" /> <xs:element ref="D05_Record" /> <xs:element ref="D06_Record" /> <xs:element ref="D07_Record" /> <xs:element ref="D08_Record" /> <xs:element ref="D09_Record" /> <xs:element ref="D10_Record" /> </xs:sequence> </xs:complexType> </xs:element> I am aware that unordered sequences may be a work in progress. I am working with daffodil retrieved a few days ago from github, --version displays Apache Daffodil (incubating) 2.5.0 Peter This e-mail and any attachment is intended for the party to which it is addressed and may contain confidential information or be subject to professional privilege. Its transmission in not intended to place the contents into the public domain. If you have received this e-mail in error, please notify us immediately and delete the email and all copies. AWTA Ltd does not warrant that this e-mail is virus or error free. By opening this e-mail and any attachment the user assumes all responsibility for any loss or damage resulting from such action, whether or not caused by the negligence of AWTA Ltd. The contents of this e-mail and any attachments are subject to copyright and may not be reproduced, adapted or transmitted without the prior written permission of the copyright owner.