<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: prepare XML with multiple loop in same level in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276791#M52767</link>
    <description>&lt;P&gt;Nicely explained&amp;nbsp;&lt;A href="https://community.qlik.com/s/profile/005390000067LRbAAM"&gt;@vapukov&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 01:27:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-11-27T01:27:56Z</dc:date>
    <item>
      <title>prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276790#M52766</link>
      <description>&lt;P&gt;The idea for this article was described several times (for example&amp;nbsp;&lt;A href="https://community.qlik.com/s/profile/005390000069RuGAAU" target="_blank"&gt;@rhall&lt;/A&gt;&amp;nbsp;) but questions is still here, so I decided to prepare an example.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;With standard Talend components like tXMLMap and/or tMSXMLOutput it is not possible to create XML with many loops on same level, like:&lt;/P&gt; 
&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;customer&amp;gt;
    &amp;lt;first_name&amp;gt;&amp;lt;/first_name&amp;gt;
    &amp;lt;last_name&amp;gt;&amp;lt;/last_name&amp;gt;
    &amp;lt;emails&amp;gt;
        &amp;lt;email&amp;gt; &amp;lt;!-- This is a Loop - multiple email for customer--&amp;gt;
            &amp;lt;email&amp;gt;&amp;lt;/email&amp;gt;
            &amp;lt;type&amp;gt;&amp;lt;/type&amp;gt;
        &amp;lt;/email&amp;gt;
    &amp;lt;/emails&amp;gt;
    &amp;lt;phones&amp;gt;
        &amp;lt;phone&amp;gt; &amp;lt;!-- This is a Loop - multiple phones for customer--&amp;gt;
            &amp;lt;phone&amp;gt;&amp;lt;/phone&amp;gt;
            &amp;lt;type&amp;gt;&amp;lt;/type&amp;gt;
        &amp;lt;/phone&amp;gt;
    &amp;lt;/phones&amp;gt;
    &amp;lt;addresses&amp;gt;
        &amp;lt;address&amp;gt;
            &amp;lt;address&amp;gt; &amp;lt;!-- This is a Loop - multiple addresses for customer --&amp;gt;
                &amp;lt;address_line_1&amp;gt;&amp;lt;/address_line_1&amp;gt;
                &amp;lt;address_line_2&amp;gt;&amp;lt;/address_line_2&amp;gt;
                &amp;lt;address_line_3&amp;gt;&amp;lt;/address_line_3&amp;gt;
                &amp;lt;postcode&amp;gt;&amp;lt;/postcode&amp;gt;
                &amp;lt;country&amp;gt;&amp;lt;/country&amp;gt;
            &amp;lt;/address&amp;gt;
        &amp;lt;/address&amp;gt;
    &amp;lt;/addresses&amp;gt;
&amp;lt;/customer&amp;gt;&lt;/PRE&gt; 
&lt;P&gt;Life case - client with 2 addresses, 2 phones and 2 emails and we restricted by requirements have exactly this structure.&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Standard tXMLMap return wrong result, tMSXMLOutput also cannot be used in this case.&lt;/P&gt; 
&lt;P&gt;DataMapper:&lt;/P&gt; 
&lt;UL&gt; 
 &lt;LI&gt;documentation is empty - possible most shorterst and not useful in class&lt;/LI&gt; 
 &lt;LI&gt;included with a most expensive license of Talend only&lt;/LI&gt; 
&lt;/UL&gt; 
&lt;P&gt;Solution which work in any version of Talend Studio (include Open Source):&lt;/P&gt; 
&lt;P&gt;we are split job to separate flows, 1 flow for main XML and 1 for each Loop:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M0pi.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/136042iEC6EEE5FD4A835C9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M0pi.png" alt="0683p000009M0pi.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;in tXMLMap_1 assign PLACEHOLDER_XXXX as element value&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1AF.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/139601i965B00EF96FF7CCB/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1AF.png" alt="0683p000009M1AF.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;output XML will contain:&lt;/SPAN&gt;&lt;/P&gt; 
&lt;PRE&gt;&amp;lt;emails&amp;gt;PLACEHOLDER_EMAIL&amp;lt;/emails&amp;gt;
&amp;lt;phones&amp;gt;PLACEHOLDER_PHONES&amp;lt;/phones&amp;gt;
&amp;lt;addresses&amp;gt;PLACEHOLDER_ADDRESS&amp;lt;/addresses&amp;gt;&lt;/PRE&gt; 
&lt;P&gt;we will use this at future steps for replace.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;each of separated flows contain tXMLMap for generate target structure:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M0zi.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/158001i4D1E8C030F6F66B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M0zi.png" alt="0683p000009M0zi.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;each output XML part must be converted from Document type to String type and cleaned from unnecessary information (tReplace_1/2/3):&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="4.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M0vk.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/143698i59C8D053F66D4D08/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M0vk.png" alt="0683p000009M0vk.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;Finally all flows joined by tMap (tMap_1) as string, in our case we make Join by customer_id:&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="5.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M1AP.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/141954i3CC21DD903A74D5C/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M1AP.png" alt="0683p000009M1AP.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;in middle part of tMap we are replace each placeholder by relevant values:&lt;/SPAN&gt;&lt;/P&gt; 
&lt;PRE&gt;row9.email==null?
row8.customer.replaceAll("&amp;lt;emails&amp;gt;PLACEHOLDER_EMAIL&amp;lt;/emails&amp;gt;", "")
:row8.customer.replaceAll("&amp;lt;emails&amp;gt;PLACEHOLDER_EMAIL&amp;lt;/emails&amp;gt;", row9.email)&lt;/PRE&gt; 
&lt;P&gt;Final XML string we can use as string to insert into database or send to API, or store to file. It is important do not convert it to Document back, because in this case Talend will add a lot of waste in document (&amp;amp;l &amp;amp; and etc)&lt;/P&gt; 
&lt;P&gt;If we need use this document as XML (Document type) in Talend on future steps - best choice store to text file and open same file but as XML.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Final proper structured XML:&lt;/P&gt; 
&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;customer&amp;gt;
    &amp;lt;first_name&amp;gt;Joe&amp;lt;/first_name&amp;gt;
    &amp;lt;last_name&amp;gt;Dow&amp;lt;/last_name&amp;gt;
    &amp;lt;emails&amp;gt;
        &amp;lt;email&amp;gt;
            &amp;lt;email&amp;gt;email3@test.com&amp;lt;/email&amp;gt;
            &amp;lt;type&amp;gt;home&amp;lt;/type&amp;gt;
        &amp;lt;/email&amp;gt;
        &amp;lt;email&amp;gt;
            &amp;lt;email&amp;gt;email4@test.com&amp;lt;/email&amp;gt;
            &amp;lt;type&amp;gt;work&amp;lt;/type&amp;gt;
        &amp;lt;/email&amp;gt;
    &amp;lt;/emails&amp;gt;
    &amp;lt;phones&amp;gt;
        &amp;lt;phone&amp;gt;
            &amp;lt;phone&amp;gt;0212579971&amp;lt;/phone&amp;gt;
            &amp;lt;type&amp;gt;home&amp;lt;/type&amp;gt;
        &amp;lt;/phone&amp;gt;
        &amp;lt;phone&amp;gt;
            &amp;lt;phone&amp;gt;0212579972&amp;lt;/phone&amp;gt;
            &amp;lt;type&amp;gt;work&amp;lt;/type&amp;gt;
        &amp;lt;/phone&amp;gt;
    &amp;lt;/phones&amp;gt;
    &amp;lt;addresses&amp;gt;
        &amp;lt;address&amp;gt;
            &amp;lt;address_line_1&amp;gt;22, Queen Street&amp;lt;/address_line_1&amp;gt;
            &amp;lt;address_line_2&amp;gt;Auckland&amp;lt;/address_line_2&amp;gt;
            &amp;lt;address_line_3&amp;gt;CBD&amp;lt;/address_line_3&amp;gt;
            &amp;lt;postcode&amp;gt;0610&amp;lt;/postcode&amp;gt;
            &amp;lt;country&amp;gt;NZ&amp;lt;/country&amp;gt;
        &amp;lt;/address&amp;gt;
        &amp;lt;address&amp;gt;
            &amp;lt;address_line_1&amp;gt;23, Queen Street&amp;lt;/address_line_1&amp;gt;
            &amp;lt;address_line_2&amp;gt;Auckland&amp;lt;/address_line_2&amp;gt;
            &amp;lt;postcode&amp;gt;0611&amp;lt;/postcode&amp;gt;
            &amp;lt;country&amp;gt;NZ&amp;lt;/country&amp;gt;
        &amp;lt;/address&amp;gt;
    &amp;lt;/addresses&amp;gt;
&amp;lt;/customer&amp;gt;&lt;/PRE&gt; 
&lt;P&gt;Conclusion:&lt;/P&gt; 
&lt;P&gt;Solution do not cover all possible cases, but add some functionality to standard Talend Studio and ideas how it possible to resolve similar cases.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;files attached:&lt;/P&gt; 
&lt;UL&gt; 
 &lt;LI&gt;Talend demo jobs&lt;/LI&gt; 
 &lt;LI&gt;mysql ddl&amp;nbsp;for test data&lt;/LI&gt; 
&lt;/UL&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 07:12:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276790#M52766</guid>
      <dc:creator>vapukov</dc:creator>
      <dc:date>2024-11-16T07:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276791#M52767</link>
      <description>&lt;P&gt;Nicely explained&amp;nbsp;&lt;A href="https://community.qlik.com/s/profile/005390000067LRbAAM"&gt;@vapukov&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 01:27:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276791#M52767</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-27T01:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276792#M52768</link>
      <description>&lt;P&gt;Hi Vapukov,&lt;/P&gt;&lt;P&gt;Thank you very much for your explanation and your example with "zip" files.&lt;BR /&gt;It's a very good job.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 08:34:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276792#M52768</guid>
      <dc:creator>HanSolo44</dc:creator>
      <dc:date>2019-05-22T08:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276793#M52769</link>
      <description>&lt;P&gt;&lt;A href="https://community.qlik.com/s/profile/005390000067LRbAAM"&gt;@vapukov&lt;/A&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thank you for sharing.&lt;/P&gt; 
&lt;P&gt;I tried to import attached zip file but getting error.&amp;nbsp; I am using Talend studio 7.1.1.&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Attached is error(No valid items to Import) I am getting while importing zip file.&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="no_valid_items.JPG" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M6Od.jpg"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/137938i9DF04CC3F96D426D/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M6Od.jpg" alt="0683p000009M6Od.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I tried to implement as per design. I have two customer , For customers XMLmap output in tlog, there is no customer id available. My understanding here is it will generate customer and corresponding xml.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Customer1| &amp;lt;xml&amp;gt;........&amp;lt;/xml&amp;gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Please correct me if I am wrong and if possible provide valid zip file.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Best Regards&lt;/P&gt; 
&lt;P&gt;Rajender Prasad&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 06:18:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276793#M52769</guid>
      <dc:creator>Rajender</dc:creator>
      <dc:date>2019-07-29T06:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276794#M52770</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;not sure, all imported fine:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-07-29 at 5.26.24 PM.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M6M4.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/139044i631DA31AEDF4B863/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M6M4.png" alt="0683p000009M6M4.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;just tested from attached archive into Studio 7.1.1&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 06:29:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276794#M52770</guid>
      <dc:creator>vapukov</dc:creator>
      <dc:date>2019-07-29T06:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276795#M52771</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import job in Talend 7.1.1 which is install in Windows 10. Does OS make any difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 07:40:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276795#M52771</guid>
      <dc:creator>Rajender</dc:creator>
      <dc:date>2019-07-29T07:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: prepare XML with multiple loop in same level</title>
      <link>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276796#M52772</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created similar&amp;nbsp; job. While generated email XML. My understanding to generated XML for each customer.&lt;/P&gt;&lt;P&gt;Customer1| &amp;lt;emails&amp;gt;&amp;lt;email&amp;gt; xx@xxx.com&amp;lt;/email&amp;gt;&amp;lt;email&amp;gt;xx2@xxx.com&amp;lt;/email&amp;gt;&amp;lt;/emails&amp;gt;&lt;/P&gt;&lt;P&gt;Customer2| &amp;lt;emails&amp;gt;&amp;lt;email&amp;gt; yy@xxx.com&amp;lt;/email&amp;gt;&amp;lt;email&amp;gt;yy2@xxx.com&amp;lt;/email&amp;gt;&amp;lt;/emails&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But getting output as follows...&lt;/P&gt;&lt;P&gt;|&amp;lt;emails&amp;gt;&amp;lt;email&amp;gt; yy@xxx.com&amp;lt;/email&amp;gt;&amp;lt;email&amp;gt;yy2@xxx.com&amp;lt;/email&amp;gt;&amp;lt;email&amp;gt; xx@xxx.com&amp;lt;/email&amp;gt;&amp;lt;email&amp;gt;xx2@xxx.com&amp;lt;/email&amp;gt;&amp;lt;/emails&amp;gt;&lt;/P&gt;&lt;P&gt;tXMLMap has "All in one" as true as per your attached images.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest. If I missed anything...&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 09:47:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/prepare-XML-with-multiple-loop-in-same-level/m-p/2276796#M52772</guid>
      <dc:creator>Rajender</dc:creator>
      <dc:date>2019-07-29T09:47:36Z</dc:date>
    </item>
  </channel>
</rss>

