You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@daffodil.apache.org by "Costello, Roger L." <co...@mitre.org> on 2019/08/28 13:39:25 UTC

dfdl:lengthKind="prefixed" -- how to allow a prefix number to be 0 to 999?

Hello DFDL community,

My input contains a string that is prefixed by a number which indicates the length of the string, e.g.,

8John Doe

The string may be anywhere from 0 characters to 999 characters. The below DFDL schema only allows a single digit for the prefix number (dfdl:lengthKind="explicit" dfdl:length="1"). How do I design the schema to allow the prefix number to be any number from 0 to 999?  /Roger

<xs:element name="input">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" type="xs:string"
                        dfdl:lengthKind="prefixed"
                        dfdl:prefixLengthType="prefix-type"
                        dfdl:prefixIncludesPrefixLength="no"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:simpleType name="prefix-type"
                        dfdl:lengthKind="explicit"
                        dfdl:length="1">
    <xs:restriction base="xs:integer" />
</xs:simpleType>


Re: dfdl:lengthKind="prefixed" -- how to allow a prefix number to be 0 to 999?

Posted by Steve Lawrence <sl...@apache.org>.
The prefix length simple type must have a lengthKind of "implicit" or
"explicit", but you need something like delimited or pattern to model
your format. So dfdl:lengthKind="prefixed" can't be used here.

Instead you would need to split it out into two separate elements.
Something like this is equivalent to prefix length, but without the same
restrictions:

<xs:element name="length" type="xs:int"
  dfdl:lengthKind="pattern"
  dfdl:lengthPattern="[0-9]{1,3}"
  dfdl:outputValueCalc="{ dfdl:valueLength(../name, 'bytes') }" />
<xs:element name="name" type="xs:string"
  dfdl:lengthKind="explicit"
  dfdl:length="{ ../length }" />

You could even put the length in a hidden group and it would give you
the exact same infoset.

Usually formats that use a prefix length have a fixed length for the
prefix length field, so your format would normally be space/zero padded,
like this:

008John Doe

In which case your simple type prefix length could have an explicit
length of three to support between 0 and 999 characters.

On 8/28/19 9:39 AM, Costello, Roger L. wrote:
> Hello DFDL community,
> 
> My input contains a string that is prefixed by a number which indicates the 
> length of the string, e.g.,
> 
> 8John Doe
> 
> The string may be anywhere from 0 characters to 999 characters. The below DFDL 
> schema only allows a single digit for the prefix number 
> (dfdl:lengthKind="explicit"dfdl:length="1"). How do I design the schema to allow 
> the prefix number to be any number from 0 to 999?  /Roger
> 
> <xs:elementname="input">
> <xs:complexType>
> <xs:sequence>
> <xs:elementname="name"type="xs:string"
>                          dfdl:lengthKind="prefixed"
>                          dfdl:prefixLengthType="prefix-type"
>                          dfdl:prefixIncludesPrefixLength="no"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> 
> <xs:simpleTypename="prefix-type"
>                          dfdl:lengthKind="explicit"
>                          dfdl:length="1">
> <xs:restrictionbase="xs:integer"/>
> </xs:simpleType>
>