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: 
VNikhil1691525655
Contributor
Contributor

Need to Generate a XML with Below Given Requirements

Hello Everyone, I am facing one issue while creating a XML in talend jobs. I need to implement a scenario and create one XML report but I am not able to generate the desired output.

Could any one please help me with this? 

As grouping along with multiple loop elements doesn't work in Talend tAdvanceFileOutputXML. How can I achieve below given scenario?

 

0695b00000lySgrAAE.png 

Labels (4)
3 Replies
Anonymous
Not applicable

@Vaidya Nikhil​ , tAdvanceFileOutputXML does not support multiple loop element, with 'Append the source xml file' option, you are able to append another loop element to an existing xml file, for example,

0695b00000lyWiXAAU.pngthis job generates a xml file format like this:

<?xml version="1.0" encoding="ISO-8859-15"?>

 

<report>

 <namereport>

  <id>1</id>

  <details>

   <name>shong</name>

   <age>11</age>

  </details>

  <details>

   <name>elise</name>

   <age>22</age>

  </details>

  <details>

   <name>ross</name>

   <age>33</age>

  </details>

  <details_old>

   <name>shong_old</name>

   <age>11_old</age>

  </details_old>

  <details_old>

   <name>elise_old</name>

   <age>22_old</age>

  </details_old>

  <details_old>

   <name>ross_old</name>

   <age>33_old</age>

  </details_old>

 </namereport>

 <namereport>

  <id>2</id>

  <details>

   <name>mike</name>

   <age>44</age>

  </details>

  <details_old>

   <name>mike_old</name>

   <age>44_old</age>

  </details_old>

 </namereport>

</report>

 

As you seen, the second loop element </details_old> are appended to an existing xml file under the same group element, but it can't generate the file format as you shown.

 

Regards

Shong

 

VNikhil1691525655
Contributor
Contributor
Author

Hello Shong, Thanks! But if you look at the output the sequence is change now the old tag needs to be just after that corresponding current value tag.

 

I also implemented the same solution and I know we can only get this output with tAdvancedFileOutputXMl.

 

I there a way or a workaround to get this desired result. I tried couple of solution but none worked.

Anonymous
Not applicable

@Vaidya Nikhil​ A workaround is to use tXMLMap to generate a Document, tXMLMap supports multiple loop element, create a XML file using the incoming Document on tFileOutputXML. The generated XML file looks like:

<?xml version="1.0" encoding="ISO-8859-15"?>

<Report>

 <id>1</id>

 <details>

  <name>shong</name>

 </details>

 <details_old>

  <name>shong_old</name>

 </details_old>

 <details>

  <name>elise</name>

 </details>

 <details_old>

  <name>elise_old</name>

 </details_old>

 <details>

  <name>ross</name>

 </details>

 <details_old>

  <name>ross_old</name>

 </details_old>

</Report>

<?xml version="1.0" encoding="ISO-8859-15"?>

<Report>

 <id>2</id>

 <details>

  <name>mike</name>

 </details>

 <details_old>

  <name>mike_old</name>

 </details_old>

</Report>

 

After generating the XML file, read the file as a string, and then replace these lines with empty value.

</Report>

<?xml version="1.0" encoding="ISO-8859-15"?>

<Report>

 

For more details, please see the below screenshots.

0695b00000lylTrAAI.png 

on tJavaRow:

output_row.content = input_row.content.toString();

 

0695b00000lylUBAAY.png0695b00000lylUkAAI.png 

Hope it helps you.

 

Regards

Shong