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>

Reply via email to