In this post, I will describe you, how to parse xml having nested loops in Talend. For that I am using below XML as source.
Source XML has list of Items from a retail store, and <item> node repeated for each item. Inside <item> node we have nested nodes for <batter> and <topping> our task is to read all the items with nested loops in their separate flow.
Image of source XML.
Sample XMl file with Nested Loops
First of all you should create metadata of your XML file, but in this post I am using XSD to populate source schema in tXMLMap.
Create new job and add tFileinputXML component and configured it as shown in Image.
Image of tFileInputXMl component.
We have set XPATH Loop to “/items” as this is the root node of XML file. then I have created one column with “Document” data type. see in Image.
tXMLMap and connect with tFileinputXML component using “Main” link.
Open tXMLMap right click on “items” node at right(source) side then select “Import from file”.
provide XSD file it will automatically create all sub nodes. like below image.
Set batter & toppiq as “loop” element by right click and select ” As loop element”
Create two outputs, “batter” and “tappinq” then drag respective columns to “batter & tappinq”
Click on “set loop function” box it will open a window wherein you have add new row and select respective loop path e.g. for “toppinq” i will select “toppinq” loop like wise batter for “batter” output.
Your Final settings looks like below image.
we are ready to get the result add tLogRow components for each of the output and execute the job it show results shown in image.
In this post, I will describe you how to split large XML into several xml.
Here is our Sample XML file. ( which is not huge but just a sample)
We are expecting three XML files from sample xml hence lets start with metadata creation for this sample file.
Once you created metadata then you can drag and drop schema to job designer. for the scenario we will choose tFileInputXML component.
Now add another component tXMLMap and link tFileInputXML to tAdvancedFileOutputXml then configure tAdvancedFileOutputXml as shown in image.
Now we have mapped our source column to output columns, but it will output all the rows in single file, to create a file for each row we have to configured tAdvancedFileOutputXML component using Advance property of component tab. use “Spit output in Several files” option with value as “1”. by doing this it will create new file for each row.
After run, this job will create three files on mention path like below.
And here is the final output.