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, and append another entity to the existing XML file with this feature. This article explains how to use this feature.
This procedure was written with:
This procedure is compatible with Data Integration releases starting from 4.2.3.
Here are the two data sources used in this example：
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 XML above, you can see that there are two loop elements in the file: person and item. However, the tAdvancedFileOutputXML component does not allow you 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. For details about the implementation process, see the following section.
Use a tFixedFlowInput to generate the person data and link it to a tAdvancedFileOutputXML. The demo job is also available as an attachment.
In the File Name field of the tAdvancedFileOutputXML_1, enter the file path to the XML file to generate, for example: D:/out.xml.
Configure its XML tree as shown below. Set person as a loop element and set class as a group element.
Use a second tFixedFlowInput_2 to generate the item data, and link it to another tAdvancedFileOutputXML_2.
In the tAdvancedFileOutputXML_2, check the Append the source xml file box to append the data to an existing XML file, D:/out.xml.
Configure the XML tree as below, set item as a loop element and set class as a group element.
Warning: This feature requires the presence of a group element in the XML tree, for example, in this case the class element is a group element. Otherwise, with no group element, an error displays as below.
Execute the Job and see whether you get the expected result as shown in the Requirement section.