How to process xml message with multiple loops ..

Five Stars

How to process xml message with multiple loops ..

Hi 

How can i process and xml with nested loops.below is my xml and expected output.I can split each loop and join using tmap but is there any other solution for this,i am using Talend open studio fro big data.

Any help would be appreciated.

 

<flighttic>
<tic_id>565662</tic_id>
<Booked_ticket_date>03-03-2018 12:45:66</Booked_ticket_date>
<person_details>
<person>
<fname>jakka</fname>
<lname>dilip</lname>
<flyinf0>
<fly>
<supplier>ETHIAD</supplier>
</fly>
</flyinf0>
<Meals>
<preference>
<mealcode>chi</mealcode>
<mealno>2</mealno>
</preference>
<preference>
<mealcode>CHI</mealcode>
<mealno>5</mealno>
</preference>
</Meals>
<sittinginfo>
<siiting>
<number>1</number>
<seatloc>6A</seatloc>
</siiting>
<siiting>
<number>2</number>
<seatloc>9B</seatloc>
</siiting>
</sittinginfo>
</person>
</person_details>
</flighttic>

 

 

tic_idBooked_ticket_datefnamelnamesuppliermealcodemealnonumberseatloc
56566203-03-2018 12:45:66jakkadilipETHIADCHI216A
56566203-03-2018 12:45:66jakkadilipETHIADCHI529B
56566203-03-2018 12:45:66jakkadilipETHIADCHI516A
56566203-03-2018 12:45:66jakkadilipETHIADCHI229B

 

 

Community Manager

Re: How to process xml message with multiple loops ..

Hi ss1417
It is impossible to read multiple loop element and join the data on one component, as you did, need to read each loop element and join the data back on a tMap.

Regards
Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business
Five Stars

Re: How to process xml message with multiple loops ..

Thanks for Reply.

Is there any possibility to do  in Enterprise edition

Nine Stars

Re: How to process xml message with multiple loops ..

Hi,

 

You can do that in data mapper.

 

You will need two maps:

1- A first one to get as many line as meal and get nested loop with sitting informations

Capture.PNG

And a second one to get the flat file:

Capture.PNG

 

You will get:

565662,03-03-2018 12:45:66,jakka,dilip,ETHIAD,chi,2,1,6A
565662,03-03-2018 12:45:66,jakka,dilip,ETHIAD,chi,2,2,9B
565662,03-03-2018 12:45:66,jakka,dilip,ETHIAD,CHI,5,1,6A
565662,03-03-2018 12:45:66,jakka,dilip,ETHIAD,CHI,5,2,9B

 

Regards.

 

Eric

 

Five Stars

Re: How to process xml message with multiple loops ..

Thanks eric but what will will the case if xml has multiple fly info as below even there it works the same package logic

<flighttic>
<tic_id>565662</tic_id>
<Booked_ticket_date>03-03-2018 12:45:66</Booked_ticket_date>
<person_details>
<person>
<fname>jakka</fname>
<lname>dilip</lname>
<flyinf0>
<fly>
<supplier>ETHIAD</supplier>
</fly>
<fly>
<supplier>quatar</supplier>
</fly>
<fly>
<supplier>singapore</supplier>
</fly>
</flyinf0>
<Meals>
<preference>
<mealcode>chi</mealcode>
<mealno>2</mealno>
</preference>
<preference>
<mealcode>CHI</mealcode>
<mealno>5</mealno>
</preference>
</Meals>
<sittinginfo>
<siiting>
<number>1</number>
<seatloc>6A</seatloc>
</siiting>
<siiting>
<number>2</number>
<seatloc>9B</seatloc>
</siiting>
</sittinginfo>
</person>
</person_details>
</flighttic>

Nine Stars

Re: How to process xml message with multiple loops ..

You can handle it too. You will need three maps.

Five Stars

Re: How to process xml message with multiple loops ..

Thanks eric.i have another use case as below 

i have xml in below format and i needed output as below,how can i do this,is there any possibility in Talend open studio.

<flighttic>
<pid>54846515522</pid>
<amount>2511</amount>
<person_details>
<person>
<fname>jakka</fname>
<lname>dilip</lname>
<flyinf0>
<fly>
<supplier>ETHIAD</supplier>
<date>2017/3/20 11:45 </date>
<mealcode>25</mealcode>
</fly>
<fly>
<supplier>American airlines</supplier>
<date>2017/3/21 22:45 </date>
<mealcode>19</mealcode>
</fly>
<fly>
<supplier>southwest</supplier>
<date>2017/3/23 14:45 </date>
</mealcode>
</fly>
<fly>
<supplier>southwest</supplier>
<date>2017/3/23 18:30</date>
<mealcode>25</mealcode>
</fly>
</flyinfo>
</person>
</person_details>
</flighttic>

pidamountfnamelanmesupplierdatemealcode
5.48E+102511jakkadilipETHIAD|American airlines|southwest|southwest2017/3/20 11:45|2017/3/21 22:45|2017/3/23 14:45|2017/3/23 18:30

25|19||25