Append the source xml file feature

 Overview

The Append the source xml file feature on the tAdvancedFileOutputXML component is used to append records to an existing XML file. This feature also resolves the can't create multiple loop elements on tAdvancedFileOutputXML at a time limitation: you can output one entity to an XML file first and append another entity to the existing XML file with this feature. This article explains how to use this feature.

Environment

This procedure was written with:

  • Talend Open Studio for Data Integration 5.3.1.0-r104014
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3

This procedure is compatible with Data Integration releases starting from 4.2.3.

Procedure

Requirement

Here are the two data sources used in this example:

person

Class_id
Person_id
Name
1 1 Shong
1 2 Elisa
2 1

Sabrina

2 2 Patrick

item

Class_id
Item_id
Item_name
1 1 item1
1 2 item2
2 1 item3

You need to read the data from the two data sources and generate an XML file as below:

<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
  <class class_id="1">
    <person>
      <id>1</id>
      <name>Shong</name>
    </person>
    <person>
      <id>2</id>
      <name>Elisa</name>
    </person>
    <item>
      <item_id>1</item_id>
      <item_name>item1</item_name>
    </item>
    <item>
      <item_id>2</item_id>
      <item_name>item2</item_name>
    </item>
  </class>
  <class class_id="2">
    <person>
      <id>1</id>
      <name>Sabrina</name>
    </person>
    <person>
      <id>2</id>
      <name>Patrick</name>
    </person>
    <item>
      <item_id>1</item_id>
      <item_name>item3</item_name>
    </item>
  </class>
</root>

From the above XML, you can see that there are two loop elements in the file: person and item. However, the tAdvancedFileOutputXML component does not allow to set multiple loop elements at a time. As a workaround, you can use the Append the source xml filefeature of the tAdvancedFileOutputXML to avoid this restriction and solve the problem. For more details about the implementation process, see the following section.

Create an example Job

  1. Use a tFixedFlowInput to generate the person data and link it to a tAdvancedFileOutputXML.



  2. In the File Name field of the tAdvancedFileOutputXML_1, enter the file path to the XML file to generate, for example: "D:/out.xml".



  3. Configure its XML tree as below. Set person as a loop element and set class as a group element.



  4. Use a second tFixedFlowInput_2 to generate the item data, link it to another tAdvancedFileOutputXML_2.



  5. In the tAdvancedFileOutputXML_2, check the Append the source xml file box to append the data to an existing XML file, "D:/out.xml".




  6. Configure the XML tree as below, set item as a loop element and set class as a group element.

Warning

Icon

This feature requires the presence of a group element in the XML tree, for example, the class element is a group element in this case. Otherwise, with no group element, an error displays as below.

The demo Job is available in the Related Files section of this article.

Execute the Job

Execute the Job and see whether you get the expected result as shown in the Requirementsection.

Related Files

  File Modified
  ZIP Archive AppendSourceXMLFile.zip Sep 29, 2013 byShicong Hong
 

Labels

Version history
Version 1 (current version) Created by Shicong Hong   Sep 29, 2013
 
 
Version History
Revision #:
1 of 1
Last update:
‎04-13-2017 10:28 PM
Updated by:
 
Labels (1)
Contributors