Multiple child loops need to be grouped in tXMLMAP

One Star

Multiple child loops need to be grouped in tXMLMAP

Hi all,
I have read a couple of posts on the forum which are similar to my post but I was not able to get a solution to my problem, hence I am opening up a new thread.
I am new to Talend. I am trying to design a job which produces XML files based on different IDs using the tXMLMap and in the later part of the job I am trying to merge all the XML files into one single XML file grouped based on IDs. Each file generated initially acts as a element in the new file in which parent tag has the id and the other elements act as the child elements. The parent tag acts as a group element.
The XML files generated based on id have multiple loop elements. Hence while creating the final XML file there is a mapping of multiple loop elements.
Illustration:
File 1:
<header>
<tag id=1>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
</header>
File 2:
<header>
<tag id=2>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
</header>
File 3:
<header>
<tag id=3>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
</header>

Final XML file:
<header>
<tag id=1>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
<tag id=3>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
<tag id=3>
<element 1> (loop element)
<element 2> (loop element)
<element 3> (loop element)
<element 4> (loop element)
</tag>
<header>

I am not able to use the "as a group element" option as the parent tags have multiple child elements with loop. Hence I am either able to get all the child elements in loop under one single id parent element. And if i try to group them I just get the first element of every child element and not the whole loop.

Does anyone have a solution how this can be done or a work around, I am stuck with this since a last couple of days.
Please help!
Seventeen Stars

Re: Multiple child loops need to be grouped in tXMLMAP

hi ,
have a look at tFileOutputMSXML :
https://help.talend.com/search/all?query=tFileOutputMSXML&content-lang=en
hope it helps
regards
laurent
One Star

Re: Multiple child loops need to be grouped in tXMLMAP

Hi laurent,
Thanks for your reply. I had tried using tFileOutputMSXML component. But it didn't work as expected. It allowed me to loop the child elements but couldn't group them. Can you please elaborate on your idea.
One Star

Re: Multiple child loops need to be grouped in tXMLMAP

The tFileOutputMSXML is not so intuitive to understand and unfortunately simple XML files used in tutorials or the Help section don't do it justice. I've used it to create a multinested (over 10 levels deep) XML file with over 400 fields.
The solution I'm presenting here used inputs from delimited files (rows of data) into the tFileOutputMSXML directly. The output was a valid, nested multi schema XML file. I've attached the summary of the solution.
1st screenshot is the XML - so you can see where you end up at the end. I've abbreviated it to be able to show the levels.
Description of file: The root node is 'BILL COLLECTION'. It contains thousands of 'BILL's. Each bill contains numerous multi-schema children nodes, which are referenced to the parent BILL by 4 keys (Bill ID, Seq_No, Batch_No & Copy_No - I'm ignoring the prefix of 'R0XXX' for simplicity). These keys are used to 'join' every incoming node into the XML component. So if you look, you will see that a BILL has a Payment Node, which could have multiple payments (each would be in a PAYMENT_ROW node). And Premise has children and grandchildren nodes etc... and each schema is different.
2nd screenshot shows the component, with all the inputs going into it. So we link starting with the main row - the one that has all BILL data.
3rd screenshot, shows you the use of the BILL node in the component. See how the columns on the right are mapped to the input fields. What you have to watch for here is how the levels are built - compare the XML...
Apologies! The screenshots don't show the lines from the left to the right, but you can follow by seeing which fields are used where in the 'Related Column'.
4th image - the next level down... Pay attention to the middle column again, and then you start seeing the grouping and looping levels...
Follow the images all the way to the last one... As you get to the bottom, you see how we build the nested nodes which are children of children etc... NOTE - every node is joined to its parent using the fields in the BILL node! Please compare the field names on the left (XML Tree column) to those in the Related Column to see how they're woven.
Please note... A requirement to making this work efficiently is to ORDER the rows by the main key fields and each successive level. The parsing engine is slow as it is, ordering the records speeds up the stitching process.
One Star

Re: Multiple child loops need to be grouped in tXMLMAP

Hi willm, can you please attach the Job, This will helps for me.. Thanks....
Seventeen Stars

Re: Multiple child loops need to be grouped in tXMLMAP

thanks willm, great & helpful explanation !
regards
laurent
One Star

Re: Multiple child loops need to be grouped in tXMLMAP

 Is it possible to have multiple loops in tWriteJSONField..?? Please give solution