Converting CSV (that has single and multivalue attributes) to XML

Highlighted
Six Stars

Converting CSV (that has single and multivalue attributes) to XML

I have a csv file that has an attribute column as shown below. The data in that column is the name of the attributes. Some of the attributes could have multiple values. I want to convert this csv into a XML file which will have multivalue tag (listing all values) for the attributes that have more than one value. I know how to convert if there is only single value for each attribute. But I am not sure how to convert the csv to xml when the attributes have single and multivalues. Could somebody please help me with this? Thanks

Input CSV:

Attribute Name, Color
aab, red
abc, red
abc, green
abc, blue
xyz, white
xyz, purple
zyx, green

 

Expected Output:

<Value AttributeID="aab">red</Value>

<MultiValue AttributeID="abc">
<Value>red</Value>
<Value>green</Value>
<Value>blue</Value>
</MultiValue>
<MultiValue AttributeID="xyz">
<Value>white</Value>
<Value>purple</Value>
</MultiValue>
<Value AttributeID="zyx">green</Value>

Six Stars

Re: Converting CSV (that has single and multivalue attributes) to XML

 

Hi 

 

Try this with  tFileInputDelimited---> tFileOutputXml  Smiley Happy

 

 

You can group the colors based on attribute name..

 

I got like this...

 

Capture.PNGCapture1.PNGCapture3.PNG

 

Six Stars

Re: Converting CSV (that has single and multivalue attributes) to XML

Hi Vignesh, thanks for your response. 

My requirement is, the output XML has to be in the following format:

<Value AttributeID="aab">red</Value>

<MultiValue AttributeID="abc">
<Value>red</Value>
<Value>green</Value>
<Value>blue</Value>
</MultiValue>
<MultiValue AttributeID="xyz">
<Value>white</Value>
<Value>purple</Value>
</MultiValue>
<Value AttributeID="zyx">green</Value>

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog