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>

2 REPLIES
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>