The spec says about dfdl:lengthKind="pattern":
The dfdl:lengthKind 'pattern' means the length of the element is
given by a regular expression specified using the dfdl:lengthPattern
property.
It says nothing about what the allowable values are, or whether the
parsed data should be considered nilled or an actual value. It just
defines the area of data that will be used to determine what goes in the
infoset for that element. Once Daffodil determines the length based on
that pattern, we can then determine if that data was nil or not.
In your case, the length of the "A" element is either 3 (for foo/bar), 1
(for the dash) or 0 (if the pattern doesn't match). Once the length is
determined, Daffodil will then inspect the data to determine if it's nil
or not, and finally evaluate your assertion to deal with the case when
the pattern didn't match anything.
Using nillable="true" and nilValue="-" is needed if you don't want a
literal dash to show up in your infoset. Otherwise, you would get an
infoset that looks like
<A>-</A>
instead of
<A xsi:nil="true" />
- Steve
On 4/27/22 6:10 PM, Roger L Costello wrote:
Hi Steve,
dfdl:lengthPattern="foo|bar|-"
That's really interesting. In my data format, the dash is to be used only to indicate there is no data
available. Doesn't that lengthPattern mean, "The allowable values for this element are foo, bar, or
dash"? If I use that lengthPattern, is there any reason to use nillable="true" and
dfdl:nilValue="-"?
/Roger
-----Original Message-----
From: Steve Lawrence <slawre...@apache.org>
Sent: Wednesday, April 27, 2022 3:04 PM
To: users@daffodil.apache.org
Subject: [EXT] Re: Bug in Daffodil?
Your pattern length must include something that matches the nil content
as well, otherwise Daffodil doesn't actaully know how long your nil
content is. So your pattern needs to look something like this:
dfdl:lengthPattern="foo|bar|-"
Additionally, because the "A" element could be nilled, you also need to
update your assertion. This is because when an element is nilled it
doesn't actually have a value, so accessing the value to compare it to
the empty string will cause an SDE. Instead, your assertion wants to be
something like this:
<dfdl:assert test="{ fn:nilled(.) or . ne '' }"/>
This asserts that either your element is nilled or its value is not the
empty string.
- Steve
On 4/27/22 2:11 PM, Roger L Costello wrote:
Hi Folks,
My input consists of one field terminated by //
The value of the field is either foo or bar.
Here is a sample input:
foo//
My DFDL schema works fine with that input.
The field is nillable and the nilValue is a hyphen. Here is a valid input:
-//
My DFDL schema fails with that input.
I specify the field using dfdl:lengthKind="pattern" and
dfdl:lengthPattern="foo|bar"
Below is my DFDL schema. Am I doing something wrong or is this a bug in
Daffodil? If so, is there a workaround? /Roger
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format
alignment="1"
alignmentUnits="bytes"
emptyValueDelimiterPolicy="none"
encoding="ASCII"
encodingErrorPolicy="replace"
escapeSchemeRef=""
fillByte="%SP;"
floating="no"
ignoreCase = "yes"
initiatedContent="no"
initiator = ""
leadingSkip="0"
lengthKind = "delimited"
lengthUnits="characters"
nilKind="literalValue"
nilValue="-"
nilValueDelimiterPolicy="none"
occursCountKind="implicit"
outputNewLine="%CR;%LF;"
representation="text"
separator=""
separatorSuppressionPolicy="anyEmpty"
sequenceKind="ordered"
textBidi="no"
textPadKind="none"
textTrimKind="none"
trailingSkip="0"
truncateSpecifiedLengthString="no"
terminator = ""
textNumberRep="standard"
textStandardBase="10"
textStandardZeroRep="0"
textNumberRounding="pattern"
textStandardExponentRep="E"
textNumberCheckPolicy="strict"
/>
</xs:appinfo>
</xs:annotation>
<xs:element name="Test" dfdl:terminator="//">
<xs:complexType>
<xs:sequence dfdl:separator="/" dfdl:separatorPosition="infix">
<xs:element name="A" type="non-zero-length-string"
nillable="true"
dfdl:lengthPattern="foo|bar"
dfdl:nilValue="-" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="non-zero-length-string" dfdl:lengthKind="pattern">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:assert test="{ . ne '' }"/>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>