Record-Separated and Field-Separated Flat File to XML
This example shows one of the most straightforward types of transformations to perform with a parser. A flat file with semicolon-separated fields and end-of-line-separated records.
Flat File Definition:
<BankRepository>
<Files>
<File>
<ID>SampleOne</ID>
<Messages>
<Message>
<IgnorePrecedingFieldSeparator>0</IgnorePrecedingFieldSeparator>
<DefaultEmptyFieldValue>
<Numeric>0</Numeric>
<Alpha></Alpha>
</DefaultEmptyFieldValue>
<DefaultAlignment>
<Numeric>RIGHT</Numeric>
<Alpha>LEFT</Alpha>
</DefaultAlignment>
<DefaultPadding>
<Numeric>0</Numeric>
<Alpha> </Alpha>
</DefaultPadding>
<DefaultTrim>
<Numeric>0</Numeric>
<Alpha>0</Alpha>
</DefaultTrim>
<Name>Sample</Name>
<TagName>Sample</TagName>
<EscapeChar/>
<RecordSeparator>\n</RecordSeparator>
<FieldSeparator>;</FieldSeparator>
<Records>
<Record>
<Name>SampleRecord</Name>
<TagName>SampleRecord</TagName>
<MinOccur>1</MinOccur>
<MaxOccur>0</MaxOccur>
<Fields>
<Field>
<Name>SampleFieldOne</Name>
<TagName>SampleFieldOne</TagName>
<DataType>Alpha</DataType>
<PaddingChar/>
<DecimalLength/>
<Alignment>LEFT</Alignment>
<StartPos>0</StartPos>
<Length>0</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
<Field>
<Name>SampleFieldTwo</Name>
<TagName>SampleFieldTwo</TagName>
<DataType>Alpha</DataType>
<PaddingChar/>
<DecimalLength/>
<Alignment>LEFT</Alignment>
<StartPos>0</StartPos>
<Length>0</Length>
<DefaultValue></DefaultValue>
<Identifier>0</Identifier>
</Field>
</Fields>
</Record>
</Records>
</Message>
</Messages>
</File>
</Files>
</BankRepository>
Input File:
Record_One_Field_Data_One;Record_One_Field_Data_Two;
Record_Two_Field_Data_One;Record_Two_Field_Data_Two;
The expected result without the surrounding envelope is:
<SampleMessage>
<SampleRecord>
<SampleFieldOne>Record_One_Field_Data_One</SampleFieldOne>
<SampleFieldTwo>Record_One_Field_Data_Two</SampleFieldTwo>
</SampleRecord>
<SampleRecord>
<SampleFieldOne>Record_Two_Field_Data_One</SampleFieldOne>
<SampleFieldTwo>Record_Two_Field_Data_Two</SampleFieldTwo>
</SampleRecord>
<SampleMessage>