Roger,

Your first element in the DateTimeIso is a string, not a numeric type.

Hence, the textNumber... properties are being ignored.


Since this first year element is fixed length, it grabs "Oct/" as the contents 
of this string. Notice how it didn't stop for any delimiter here, because the 
field isn't delimited. It's fixed length.


At that point things are off the rails. All these fields are just grabbing 
fixed length strings, and eventually it gets to where it expects a separator 
again, but it's consumed them all.


You can fix that by making year an xs:int, and similarly the other fields that 
are supposed to be integers.


(Note: a recent improvement to Daffodil coming out next release will issue you 
a warning about these properties that you think are being used, but are 
actually being ignored.)


I also suggest using dfdl:calendarPattern and a xs:dateTime to parse your 
date-time data, as that will do much more relevant checking for a well-formed 
date/time for you, and you'll get one element of type dateTime versus a flock 
of elements for each sub-part of the date/time information.


-mikeb

________________________________
From: Costello, Roger L. <[email protected]>
Sent: Monday, June 17, 2019 11:16:50 AM
To: [email protected]
Subject: The second choice branch is never used ... why is that?


Hello DFDL community,



My input file contains three fields, separated by slash.



The first and last fields contain strings.



The middle field contains either an ISO date/time or a 3-letter month (Jan, 
Feb, etc.)



So, the middle field is a choice.



This input



Birthday/20190617T182530Z/John's birthday



Produces this XML



<input>
  <title>Birthday</title>
  <date>
    <DateTimeIso>
      <Year>2019</Year>
      <MonthNumeric>06</MonthNumeric>
      <Day>17</Day>
      <TimeSeparator>T</TimeSeparator>
      <HourTime>18</HourTime>
      <MinuteTime>25</MinuteTime>
      <SecondTime>30</SecondTime>
      <TimeZoneZulu>Z</TimeZoneZulu>
    </DateTimeIso>
  </date>
  <note>John's birthday</note>
</input>



But this input



New tasking/Oct/Start Fiscal Year



Results in this error message



[error] Parse Error: Separator '/' not found.



First Question: Why is that? Why can’t Daffodil recognize that “Oct” doesn’t 
match my schema’s first choice branch and then use the second choice branch? I 
noticed that if I reverse the choice branches in my DFDL schema, then this 
input parses fine, but then the first input fails.



Below is my DFDL schema.



Second Question: Is there a better way to express the file format than how my 
DFDL schema does it?  /Roger



<xs:element name="input">
    <xs:complexType>
        <xs:sequence dfdl:separator="/" dfdl:separatorPosition="infix">
            <xs:element name="title" type="xs:string" />
            <xs:element name="date">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="DateTimeIso">
                            <xs:complexType>
                                <xs:sequence dfdl:separator="">
                                    <xs:element name="Year" type="xs:string"
                                        dfdl:length="4" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="####" />
                                    <xs:element name="MonthNumeric" 
type="xs:string"
                                        dfdl:length="2" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="##"  />
                                    <xs:element name="Day" type="xs:string"
                                        dfdl:length="2" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="##" />
                                    <xs:element name="TimeSeparator" 
type="xs:string"
                                        dfdl:length="1" 
dfdl:lengthKind="explicit" />
                                    <xs:element name="HourTime" type="xs:string"
                                        dfdl:length="2" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="##" />
                                    <xs:element name="MinuteTime" 
type="xs:string"
                                        dfdl:length="2" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="##" />
                                    <xs:element name="SecondTime" 
type="xs:string"
                                        dfdl:length="2" 
dfdl:lengthKind="explicit"
                                        dfdl:textNumberCheckPolicy="strict"
                                        dfdl:textNumberPattern="##" />
                                    <xs:element name="TimeZoneZulu" 
type="xs:string"
                                        dfdl:length="1" 
dfdl:lengthKind="explicit" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="MonthName" type="xs:string" 
dfdl:length="3"
                            dfdl:lengthKind="explicit" />
                    </xs:choice>
                </xs:complexType>
            </xs:element>
            <xs:element name="note" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:element>






Reply via email to