Append the source XML file feature
This article explains how to append a source xml file.
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 procedure was written with Talend Open Studio for DI 6.5.
Person
Class_id | Person_id | Name |
---|---|---|
1 | 1 | Shong |
1 | 2 | Elisa |
2 | 1 | Sabrina |
2 | 2 | Patrick |
Item
Class_id | Person_id | 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>
<name>Shong>
<person>
<id>2>
<name>Elisa>
<person>
<item>
<item_id>1>
<item_name>item1>
<item1>
<item>
<item_id>21>
<item_name>item2>
<item>
</class>
<class class_id="2">
<person>
<id>1>
<name>Sabrina>
</person>
<person>
<id>2>
<name>Patrick>
<person>
<item>
<item_id>1>
<item_name>item3>
</item>
</class>
</root>
Tip: 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 file feature of the
tAdvancedFileOutputXML to avoid this restriction and
solve the problem.
Configuring the first subjob to generate an XML file
This Job will use the following components:
- two tFixedFlowInput components to generate the person and the item data from a text file and
- two tAdvancedFileOutpuXML to generate an XML file and append its data.