Hi!

I'm trying to create my first DFDL schema to parse a fixed column format.
The format may change from one line to the other depending on the first
character of the line. Some lines are optional, therefore I use
minOccurs="0" and dlfl:occursCountKind="implicit". Here is the schema:

<?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/";
           xmlns:ex="http://example.com";
           xmlns:ama="http://www.amadeus.com";
           targetNamespace="http://www.amadeus.com";
           elementFormDefault="unqualified">

    <xs:include
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
    <xs:include schemaLocation="IT01.dfdl.xsd" />
    <xs:include schemaLocation="IT02.dfdl.xsd" />
    <xs:include schemaLocation="IT03.dfdl.xsd" />
    <xs:include schemaLocation="IT05.dfdl.xsd" />

    <xs:annotation>
        <xs:appinfo source="http://www.ogf.org/dfdl/";>
            <dfdl:format alignment="1"
                         alignmentUnits="bytes"
                         encoding="ASCII"
                         encodingErrorPolicy="replace"
                         escapeSchemeRef=""
                         floating="no"
                         ignoreCase="no"
                         initiatedContent="no"
                         initiator=""
                         leadingSkip="0"
                         lengthKind="implicit"
                         lengthUnits="bytes"
                         outputNewLine="%LF;"
                         representation="text"
                         separator=""
                         separatorSuppressionPolicy="never"
                         sequenceKind="ordered"
                         terminator=""
                         textBidi="no"
                         textPadKind="none"
                         textStringJustification="center"
                         textStringPadCharacter="%WSP;"
                         textTrimKind="padChar"
                         trailingSkip="0"
                         truncateSpecifiedLengthString="no"/>
        </xs:appinfo>
    </xs:annotation>

    <xs:element name="records" type="ama:Records" />

    <xs:complexType name="Records">
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="postfix">
            <xs:element name="it01" minOccurs="0" maxOccurs="1"
type="ama:IT01" dfdl:initiator="1" dfdl:occursCountKind="implicit" />
            <xs:element name="record" type="ama:Record" minOccurs="1"
dfdl:occursCountKind="implicit" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Record">
        <xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="postfix">
            <xs:element name="it02" type="ama:IT02" dfdl:initiator="2"
dfdl:occursCountKind="implicit" />
            <xs:element name="it03" minOccurs="0" type="ama:IT03"
dfdl:initiator="3" dfdl:occursCountKind="implicit" />
            <xs:element name="it05" minOccurs="0" type="ama:IT05"
dfdl:initiator="5" dfdl:occursCountKind="implicit" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>


A file would look like this:

1......
2......
5......

Elements it01 (line starting with '1') and it02 (line starting with '2')
are parsed successfully. Element it03 is missing, but since it is optional
it is OK. The problem is that the Daffodil raises an error saying it has
not found initiator '3'. How to make the initiator optional?

Patrick.

Reply via email to