Padding and alignment
When a field has fixed length and the data is shorter than the specified length, the data must be padded with additional characters for it to be able to reach the specified length. These examples show transformations that use padding and alignment.
Flat File with Padding to XML
This example shows a transformation in which the padding of the flat file and left alignment is removed in the generated XML output.
Flat File Definition:
<BankRepository>
<Files>
<File>
<ID>SampleEight</ID>
<Messages>
<Message>
<IgnorePrecedingFieldSeparator>1</IgnorePrecedingFieldSeparator>
<DefaultEmptyFieldValue>
<Numeric>0</Numeric>
<Alpha></Alpha>
</DefaultEmptyFieldValue>
<DefaultAlignment>
<Numeric>RIGHT</Numeric>
<Alpha>LEFT</Alpha>
</DefaultAlignment>
<DefaultPadding>
<Numeric>0</Numeric>
<Alpha>X</Alpha>
</DefaultPadding>
<DefaultTrim>
<Numeric>1</Numeric>
<Alpha>1</Alpha>
</DefaultTrim>
<Name>TopNode</Name>
<TagName>TopNode</TagName>
<EscapeChar/>
<RecordSeparator>\n</RecordSeparator>
<FieldSeparator></FieldSeparator>
<Records>
<Record>
<Name>RecordOne</Name>
<TagName>RecordOne</TagName>
<MinOccur>1</MinOccur>
<MaxOccur>0</MaxOccur>
<Fields>
<Field>
<Name>Field1</Name>
<TagName>Field1</TagName>
<DataType>Alpha</DataType>
<StartPos>1</StartPos>
<Length>3</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
<Field>
<Name>Field2</Name>
<TagName>Field2</TagName>
<DataType>Alpha</DataType>
<StartPos>4</StartPos>
<Length>3</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
</Fields>
</Record>
</Records>
</Message>
</Messages>
</File>
</Files>
</BankRepository>
Input file:
XXAXXB
XCXDXX
The expected result is:
<TopNode>
<RecordOne>
<Field1>XXA</Field1>
<Field2>XXB</Field2>
</RecordOne>
<RecordOne>
<Field1>XC</Field1>
<Field2>D</Field2>
</RecordOne>
</TopNode>
XML to Flat File with Padding
This example shows a transformation of an XML file to a flat file output with padding. Fields are padded when they are too short.
Flat File Definition:
<BankRepository>
<Files>
<File>
<ID>SampleEight</ID>
<Messages>
<Message>
<IgnorePrecedingFieldSeparator>1</IgnorePrecedingFieldSeparator>
<DefaultEmptyFieldValue>
<Numeric>0</Numeric>
<Alpha></Alpha>
</DefaultEmptyFieldValue>
<DefaultAlignment>
<Numeric>RIGHT</Numeric>
<Alpha>LEFT</Alpha>
</DefaultAlignment>
<DefaultPadding>
<Numeric>0</Numeric>
<Alpha>X</Alpha>
</DefaultPadding>
<DefaultTrim>
<Numeric>1</Numeric>
<Alpha>1</Alpha>
</DefaultTrim>
<Name>TopNode</Name>
<TagName>TopNode</TagName>
<EscapeChar/>
<RecordSeparator>\n</RecordSeparator>
<FieldSeparator></FieldSeparator>
<Records>
<Record>
<Name>RecordOne</Name>
<TagName>RecordOne</TagName>
<MinOccur>1</MinOccur>
<MaxOccur>0</MaxOccur>
<Fields>
<Field>
<Name>Field1</Name>
<TagName>Field1</TagName>
<DataType>Alpha</DataType>
<StartPos>1</StartPos>
<Length>3</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
<Field>
<Name>Field2</Name>
<TagName>Field2</TagName>
<DataType>Alpha</DataType>
<StartPos>4</StartPos>
<Length>3</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
</Fields>
</Record>
</Records>
</Message>
</Messages>
</File>
</Files>
</BankRepository>
Input File:
<TopNode>
<RecordOne>
<Field1>XXA</Field1>
<Field2>XXB</Field2>
</RecordOne>
<RecordOne>
<Field1>XC</Field1>
<Field2>D</Field2>
</RecordOne>
</TopNode>
The expected result is:
XXAXXB
XCXDXX