One Star

Mapping multiple tabular columns (source) to a xml loop element

Hi Team:
I have a requirement to extract data from database and export to xml. The tricky part is each column name should go to a loop element's attribute in an xml.
Example :
Input : 
Database columns :
Output : 
XML as below
<Description type="NAME">George</Description>
<Description type="SEX">M</Description>
<Description type="AGE">61</Description>
<Description type="COUNTRY">USA</Description>
<Description type="NAME">CHING</Description>
<Description type="SEX">M</Description>
<Description type="AGE">45</Description>
<Description type="COUNTRY">CHINA</Description>
Key points:
1. Based on each record in DB table ,an Employee entity has to be generated in xml.
2. DB Column name should go to xml Description's attribute "type". Description is a loop element.
Please advice how to proceed.
Community Manager

Re: Mapping multiple tabular columns (source) to a xml loop element

You need to iterate each record and append it to existing XML file. The job looks like:
father job:
trunJob: pass current record to child job, and call the child job
child job:
on tFixedFlowInput: generate the current record passed from father job.
on tNormalizedRow: normalized one row to multiple rows. for example:



on tMap: add a sequence number for each line, add a new column called type in the output table and set its value based the line number, for exmaple:
Var.line%4==0?"COUNTRY": (Var.line%4==3?"AGE": (Var.line%4==2?"SEX":"NAME"))

tAdvancedFileOutputXML: generate the XML file if current record is the first line, otherwise, append current record to an existing XML file. see
Talend | Data Agility for Modern Business
One Star

Re: Mapping multiple tabular columns (source) to a xml loop element

Thanks for your reply Shong!
On top of the above requirement, there are millions of (DB)records of that kind of structure.
What would be the fastest approach ? 
I tried something like tMySqlInput ->main -> tAdvanceOutputXml(some intermediate xml format based on db columns as elements) then applied tXsl to get the desired format.
But it takes 2 hours of times to complete the job for completing the 300 million records.
I am looking for a better solution. Please guide me.