Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
rubenfasilva
Contributor
Contributor

From csv to xml file

Hello

I have simple job to do, maybe it's very simple, but I am not able to get it.

I want to transform a csv file into xml.

tflieInputdelimited -> tmap -> tadvancedfileoutputxml.

My csv is:

sku:warehouse;qty

a;ny;2

b;ca;3

c;la;1

I am having this output:

<body>

 <products>

 <product>

  <sku>a</sku>

  <warehouse>ny</warehouse>

  <qty>2</qty>

 </product>

 <product>

  <sku>b</sku>

  <warehouse>ca</warehouse>

  <qty>3</qty>

 </product>

 <product>

  <sku>c</sku>

  <warehouse>la</warehouse>

  <qty>1</qty>

 </product>

 </products>

</body>

But I want this output

<body>

 <products>

 <product>

  <sku>a</sku>

  <warehouse>ny</warehouse>

  <qty>2</qty>

  <sku>b</sku>

  <warehouse>ca</warehouse>

  <qty>3</qty>

  <sku>c</sku>

  <warehouse>la</warehouse>

  <qty>1</qty>

 </product>

 </products>

</body>

Is this possbile?

Labels (4)
2 Replies
Anonymous
Not applicable

Hello @Ruben Silva​ ,

It's impossible to do that by using tAdvancedFileOutputXML component.

To achieve your goal, it need to do additional steps to read the xml root content as string then replace "</product>

 <product>" as empty like the below

output_row.xml= input_row.xml.replaceAll("<\\/product>\\s+<product>","");

 

0695b00000aD09wAAC.png 

rubenfasilva
Contributor
Contributor
Author

Thank you for you answer.

In the meantime, the team is asking for a json file with an array of details like this:

 [

{

    "sku" : "A",

    "warehouse" : "NY",

    "qty" : 2

},

{

    "sku" : "B",

    "warehouse" : "CA",

    "qty" : 3

},

{

    "sku" : "C",

    "warehouse" : "LA",

    "qty" : 1

 }

]

 

I never worked with json files before, can you show me steps?

Thank you!