Search code examples
xmltalendtalend-mdm

Talend extract xml for each row


In my data source I have records with XML content that I want to extract and duplicate rows :

Data Source

id | content 

100 | <?xml version="1.0" encoding="utf-8"?><RepeaterData><Version /><Items><Item><Years>2018</Years><data>110</data></Item><Item><Years >2019</Years><data>200</data></Item></Items></RepeaterData>

I want to get an out put like :

100 | 2018 | 110

100| 2019 | 200

which component could I use ? Any help please ?


Solution

  • Here's how you can do it :

    enter image description here

    First, iterate on your rows, and for each row read the xml column and extract the fields you want from it using tExtractXMLField. Then inside the tMap retrieve the ID of the current row that was set by tFlowToIterate.

    And the result :

    .---+----+----.
    |  tLogRow_1  |
    |=--+----+---=|
    |id |year|data|
    |=--+----+---=|
    |100|2018|110 |
    |100|2019|200 |
    '---+----+----'