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>

 

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now