Weird flat file mapping to XML

I must map a flat file that has the following format to a XML structure. I have made a template (included in attachment) and the file is loading OK in the record so I have all my data in the pipeline. The file (an invoice) has 1 field per line instead of having many fields on 1 line. So for detail records, it goes like this :

301 0001
305 MMM651
310 Product description
325 5
335 2.39
301 0002
305 MMM652
310 Prod desc 2
325 10
335 4.35

My goal is to load this to an XML structure like this :

<invoiceline>
<linenumber>
<number>0001</number>
</linenumber>
<itemquantity>
<quantity>000005</quantity>
</itemquantity>
<productid>
<id>MMM651</id>
<description>Prodcut Description</description>
</productid>
<unitprice>
<amount>23900</amount>
</unitprice>
</orderline>
<orderline>
<linenumber>
<number>0002</number>
</linenumber>
<itemquantity>
<quantity>000010</quantity>
</itemquantity>
<productid>
<id>MMM652</id>
<description>Prod desc 2</description>
</productid>
<unitprice>
<amount>43500</amount>
</unitprice>
</orderline>

I’ve tried many LOOP, MAP combined with appendToRecordList to a temp records and/or directly to my XML structure but was not able to produce an output that was making sense. The best I could do was having the correct line detail structure but with the same data in each detail line

I’m sure somebody in here has done something similar ?
Thanks for your help !

flat file invoice template
AlphaInvoiceTemplate.xml (14.6 k)

Hi,

Your case is like a VDA format file used in europe. or EDIFACT groups of DTM and SCC. See if you can define… 305,310 325 and 335 as subelements under 301 and if that work, or if you can define them as a group.

Mathieu,

Have you tried using the “out-array” feature of the LOOP.

Your “in-array” is the source record you created from the template. The “out-array” is the target record you will eventually create the XML with" . For example, within the LOOP - map the source record data to the target record data , as a single record (not recordlist) called linenumber. You set “out-array” of the LOOP to be the same name as the target record - so in this case - call it “linenumber”. At the end of the loop, you should have a record list of “linenumber”.

sorry - I just noticed that “linenumber” is not the right example from your XML - should be “invoiceline”.

So I don’t really need to play with templates right ?
Let me try those suggestions and get back to you…

I changed my template (see attachment) to include some subelements under my 300 record but now some data in going into unDefData instead of going into the correct 301/305/… records. I must do something wrong …?

new flat file with subelements
AlphaInvoiceTemplate.xml (14.9 k)

Here’s a screenshot of my record with unDefData

Hi,

Have you found a solution to your problem?