Subject:Flat file conversion to XML Author:Francois Malan Date:16 Jul 2009 06:56 PM
I am reviewing the StylusStudio software capabilities to convert a flat file(txt) to XML:
We have a text file with statement information for different accounts and would like to produce a separate statement for each customer account.
The text file contains data elements (e.g. RecordType, Customer Id, Lastname & Firstname) which are all on separate lines and can be identified through unique matching patterns. (e.g. 101, 102, 104)
999 Indicates the start of a new statement.
The first 25 characters are a combination of prefixes and matching patterns and the data element is in the last 25 characters and then terminated by a CR/LF.
Example text file extract is:
99900000000000000000000000000000000000000000000000
101 000000000000000000111456789
102 000000000000000000MR JOHN
103 000000000000000000SMITH
104 21 MAY 478887 CHEQUE PAYMENT 41.00
104 22 MAY 478888 CHEQUE PAYMENT 42.00
104 23 MAY 478889 CHEQUE PAYMENT 43.00
99900000000000000000000000000000000000000000000000
101 000000000000000000222456679
102 000000000000000000MR DAVID
103 000000000000000000DOE
104 14 MAY 508888 CHEQUE PAYMENT 31.00
The desired outcome must be a single file with multiple XML definitions, each Statement line to represent the XML customer statement.
<?xml version="1.0"?>
<StatementList>
<Statement>
<AccNumb>111456789</AccNumb>
<Mod05>
<FirstName>MR JOHN</FirstName>
<LastName>SMITH</LastName>
</Mod05>
<Mod10>
<TxLine>21 MAY 478887 CHEQUE PAYMENT 41.00</TxLine>
<TxLine>22 MAY 478888 CHEQUE PAYMENT 42.00</TxLine>
<TxLine>23 MAY 478889 CHEQUE PAYMENT 43.00</TxLine>
</Mod10>
</Statement>
<Statement>
<AccNumb>222456679</AccNumb>
<Mod05>
<FirstName>MR DAVID</FirstName>
<LastName>DOE</LastName>
</Mod05>
<Mod10>
<TxLine>14 MAY 508888 CHEQUE PAYMENT 31.00</TxLine>
</Mod10>
</Statement>
</StatementList>
Issues that I currently have are:
1. Formatting the XML to get desired outcome.
2. Allocating substring values of a row to a XML field
Subject:Flat file conversion to XML Author:Tony Lavinio Date:21 Jul 2009 03:44 PM
We do it in two steps.
The CustomXMLConverter is used to build the map from the text to a
simple XML representation, and then XQuery is used to rearrange the
output into the nested structure.
This lets each tool do one thing well.
The attached .zip file contains a m.prj project file for Stylus Studio
which includes a .conv converter map and a .xquery that uses it to do
the job.
Just open the .xquery program and run it to see the results.