One Star

Advanced XML with different loops

Hello,
I have a scenario using XML files in which I have to set up something like this :
I have 3 data sources. Invoice_Header, Invoice_Line and Invoice_Line_Tax
My Invoice_Header schema is something like
ID,
TotalAmt,
Description
My Invoice_Line schema is something like
LineID,
HeaderID,
LineAmt
My Invoice_Line_Tax schema is something like
TaxID,
LineID,
TaxPerct,
TaxAmt
I would like to read the 3 separate tables and come up with one single XML at the end.
My problem is that I can't figure out a way to join the values because of different loops...for 1 invoice, I might have N lines, and for 1 Line I might have N Taxes
I've attached some handmade xml's that I'm working with to try to figure this out, there are the separated XML's and the final structure I would like to get to. It's something like this :
<Invoices>
<Invoice>
<ID/>
<TotalAmt/>
<Description/>
<InvoiceLines> /* Loop 1-N */
<Line>
<LineID/>
<LineAmt/>
<LineTaxes> /* Second Loop 1-N */
<Tax>
<TaxID/>
<TaxPerct/>
<TaxAmt/>
<Tax/>
</LineTaxes>
</Line>
</InvoiceLines>
</Invoice>
</Invoices>
Does anybody have any kind of ideas or something for me to try out ? I'm currently going for the tJava component and appending the strings for 3 different files into one...but that's obviously something I would like to avoid.
Thanks!
2 REPLIES
One Star

Re: Advanced XML with different loops

See http://www.talendforge.org/forum/viewtopic.php?id=7618 for an answer. To merge the output in your tree style you need to have the non loop part the same in the multiple roots so that they can be matched. I think there is a better example from Shong but I couldn't find it.