Alignment can't really be used in this case (technically it might be
possible, but definitely not the clearest). Alignment is really just for
specify that a field must start on some multiple of a bit positive, such
as 2-word. This is usually used when you have fields that are non-byte
lengths, but following fields must start on a byte length.

The best way to model this is to model each field as fixed length string
that is the length of the column, and then specify a pad character and
text justification to remove the column pading. For example, something
like this:

  <dfdl:format
    ...
    lengthKind="explicit"
    textPadKind="padChar"
    textTrimKind="padChar"
    textStringJustification="left"
    textStringPadCharacter="%SP;" />

  ...

  <xs:element name="record">
    <xs:complexType>
      <xs:sequence dfdl:separator="%NL;">
        <xs:element name="fruit" type="xs:string" dfdl:length="30" />
        <xs:element name="color" type="xs:string" dfdl:length="30" />
        <xs:element name="plant" type="xs:string" dfdl:length="30" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

So each field has a fixed length, the contents of those fields are left
justified, and so padded with spaces on the right. During parse,
Daffodil will trim off the spaces before adding to the infoset, and on
unparse will pad back the string to fit the column size. So the infoset
looks something like:

  <record>
    <fruit>orange</fruit>
    <color>orange</color>
    <plant>tree</plant>
  </record>
  <record>
    <fruit>banana</fruit>
    <color>yellow</color>
    <plant>tree</plant>
  </record>
  <record>
    <fruit>raspberry</fruit>
    <color>red</color>
    <plant>bush/plant>
  </record>

On 12/15/20 10:32 AM, Roger L Costello wrote:
> Hi Folks,
> 
> Suppose that a data format about fruits has data like this:
> 
> orange        orange          tree
> banana        yellow          tree
> raspberry     red             bush
>                              
> There are 3 columns. The data for the first column starts in column 1. The 
> data for the second column starts in column 30. The data for the third column 
> starts in column 60.
> 
> Can this data format be specified using the alignment property?
> 
> I've always thought that the alignment property was exclusively for binary 
> data formats, but if it can be used to describe columnar text data formats, 
> that would be pretty cool.
> 
> /Roger
> 

Reply via email to