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 2020/05/15 11:32:28 UTC

Does Daffodil support textPadKind="padChar" and textStringPadCharacter?

Hi Folks,

My input contains a person's name. The name is padded on the left and right with the forward slash ( / ) symbol, e.g.

///John///

I used textPadKind="padChar" and textStringPadCharacter="/" to direct Daffodil to remove the forward slashes:

<xs:element name="SimpleDataFormat">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" type="xs:string" 
                dfdl:textPadKind="padChar"
                dfdl:textStringPadCharacter="/"
            />
        </xs:sequence>
    </xs:complexType>
</xs:element>

Unfortunately, no slashes are removed:

<SimpleDataFormat>
  <name>///John///</name>
</SimpleDataFormat>

Below is my complete schema. What am I doing wrong, please?  /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/"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    elementFormDefault="qualified">
    
    <xs:annotation>
        <xs:appinfo source="http://www.ogf.org/dfdl/">
            <dfdl:format
                textBidi="no"
                separatorSuppressionPolicy="never"
                floating="no"
                encodingErrorPolicy="replace"
                outputNewLine="%CR;%LF;"
                leadingSkip="0" 
                trailingSkip="0"
                alignment="1" 
                alignmentUnits="bytes"
                textPadKind="none"
                textTrimKind="none" 
                truncateSpecifiedLengthString="no"
                escapeSchemeRef=""
                
                representation="text"
                encoding="ASCII"
                lengthKind = "delimited"
                initiator = ""
                terminator = ""
                separator = ""
                ignoreCase = "yes"
                sequenceKind="ordered"
                initiatedContent="no"
                lengthUnits="characters"
                textStringJustification="center"
                
            />
        </xs:appinfo>
    </xs:annotation>
    
    <xs:element name="SimpleDataFormat">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string" 
                    dfdl:textPadKind="padChar"
                    dfdl:textStringPadCharacter="/"
                />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    
</xs:schema>


Re: Does Daffodil support textPadKind="padChar" and textStringPadCharacter?

Posted by Steve Lawrence <sl...@apache.org>.
dfdl:textPadKind determines how padding is added during unparsing.

dfdl:textTrimKind determines how padding is removed during parsing.

So you need textTrimKind. Adding dfdl:textTrimKind="padChar" to the name
element should get you the behavior you're looking for.

- Steve

On 5/15/20 7:32 AM, Costello, Roger L. wrote:
> Hi Folks,
> 
> My input contains a person's name. The name is padded on the left and right with the forward slash ( / ) symbol, e.g.
> 
> ///John///
> 
> I used textPadKind="padChar" and textStringPadCharacter="/" to direct Daffodil to remove the forward slashes:
> 
> <xs:element name="SimpleDataFormat">
>     <xs:complexType>
>         <xs:sequence>
>             <xs:element name="name" type="xs:string" 
>                 dfdl:textPadKind="padChar"
>                 dfdl:textStringPadCharacter="/"
>             />
>         </xs:sequence>
>     </xs:complexType>
> </xs:element>
> 
> Unfortunately, no slashes are removed:
> 
> <SimpleDataFormat>
>   <name>///John///</name>
> </SimpleDataFormat>
> 
> Below is my complete schema. What am I doing wrong, please?  /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/"
>     xmlns:fn="http://www.w3.org/2005/xpath-functions"
>     elementFormDefault="qualified">
>     
>     <xs:annotation>
>         <xs:appinfo source="http://www.ogf.org/dfdl/">
>             <dfdl:format
>                 textBidi="no"
>                 separatorSuppressionPolicy="never"
>                 floating="no"
>                 encodingErrorPolicy="replace"
>                 outputNewLine="%CR;%LF;"
>                 leadingSkip="0" 
>                 trailingSkip="0"
>                 alignment="1" 
>                 alignmentUnits="bytes"
>                 textPadKind="none"
>                 textTrimKind="none" 
>                 truncateSpecifiedLengthString="no"
>                 escapeSchemeRef=""
>                 
>                 representation="text"
>                 encoding="ASCII"
>                 lengthKind = "delimited"
>                 initiator = ""
>                 terminator = ""
>                 separator = ""
>                 ignoreCase = "yes"
>                 sequenceKind="ordered"
>                 initiatedContent="no"
>                 lengthUnits="characters"
>                 textStringJustification="center"
>                 
>             />
>         </xs:appinfo>
>     </xs:annotation>
>     
>     <xs:element name="SimpleDataFormat">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="name" type="xs:string" 
>                     dfdl:textPadKind="padChar"
>                     dfdl:textStringPadCharacter="/"
>                 />
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
>     
> </xs:schema>
>