Description
This reported by Jonathan Cranford:
I duplicated a problem Roger Costello ran into a few weeks ago in the 0.9.1 build. I based the test schema on one of the OGF tutorials. See attached for all files.
First, the working schema address.xsd in action:
C:\...\test> \users\jcranford\share\java\daffodil-0.9.1\bin\daffodil.bat parse -s address.xsd address.txt
<addresses>
<address>
<houseNumber>118</houseNumber>
<street>Ridgewood Circle</street>
<city>Rochester</city>
<jurisdiction>
<state>NY</state>
</jurisdiction>
</address>
<address>
<houseNumber>25</houseNumber>
<street>The Hundred</street>
<city>Romsey</city>
<jurisdiction>
<county>Hampshire</county>
</jurisdiction>
</address>
<address>
<houseNumber>279</houseNumber>
<street>Lakeside Road</street>
<city>Toronto</city>
<jurisdiction>
<province>Ontario</province>
</jurisdiction>
</address>
</addresses>
If you look at address.xsd, the key for us is the jurisdiction element - it can contain a state or county or province.
Now for the broken one: address-optional-choice.xsd
The only difference between the two schemas is in the jurisdiction element; address-optional-choice.xsd has the attributes in red below, but they’re missing in address.xsd. In short, all branches of the choice are now optional.
<xs:element dfdl:initiator="state:" dfdl:occursCountKind="implicit" minOccurs="0" name="state" type="xs:string"/>
<xs:element dfdl:initiator="county:" dfdl:occursCountKind="implicit" minOccurs="0" name="county" type="xs:string"/>
<xs:element dfdl:initiator="province:" dfdl:occursCountKind="implicit" minOccurs="0" name="province" type="xs:string"/>
The DFDL spec explicitly says that no branches in a choice may be optional; that is, minOccurs must be greater than 0.
Now, the faulty schema in action:
C:\...\test> \users\jcranford\share\java\daffodil-0.9.1\bin\daffodil.bat parse -s address-optional-choice.xsd address.txt
[error] Parse Error: All alternatives failed. Reason(s): List(Parse Error: Alternative failed.
Reason(s): List(Parse Error: Sep('%CR;%LF;') - element.address: Delimiter not found!
Schema context: element.address Location in file:/C:/Users/jcranford/IBM/wmbt80/workspace/test/address-optional-choice.xsd
Data location was preceding byte 61
UTF-8 text starting at byte 56 is: (NY]
[house:25*street:The Hundred*city:R)
…
I trimmed a bunch of noisy diagnostic output and bolded what I think is the important part. I interpret this to mean that it couldn’t find an alternative to match. The diagnostic output shows that it choked on "NY"; it didn’t know how to parse it.
I think what Daffodil should do is detect minOccurs=0 branches in a choice and raise a Schema Definition Error, with some error message like "A choice cannot contain optional elements, nor can a choice be optional" (credit to Roger for the wording). Instead, what it appears to be doing is failing the parse with a parse error.
It is interesting to note that I couldn’t even run this example in IBM’s MBTK; it flags the optional branch as an error in address-optional-choice.xsd.
Fyi,
-Jonathan Cranford