Append the source XML file feature

author
Shicong Hong
EnrichVersion
6.5
EnrichProdName
Talend Open Studio for Big Data
Talend Data Fabric
Talend Real-Time Big Data Platform
Talend Data Services Platform
Talend Open Studio for ESB
Talend Big Data Platform
Talend Big Data
Talend ESB
Talend Open Studio for MDM
Talend MDM Platform
Talend Open Studio for Data Integration
Talend Data Integration
Talend Data Management Platform
task
Design and Development > Third-party systems > XML components
Data Quality and Preparation > Third-party systems > XML components
Data Governance > Third-party systems > XML components
EnrichPlatform
Talend Studio

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.

Procedure

  1. Drop a tFixedFlowInput and a tAdvancedFileOutputXML from the Palette onto the design workspace. Connect the two components using a Row > Main link.
  2. Double-click on tFixedFlowInput to display its Basic settings and select the Use Inline Content (delimited file). In the Content field, add the following information:
    1;1;Shong
    1;2;Elisa
    2;1;Sabrina
    2;2;Patrick
  3. Click the Edit Schema button and set the three-column schema.
  4. When prompted, click OK to accept the propagation or click afterward on the Sync columns button in the tJavaRow Basic settings view.
  5. Click the Configure its XML tree button to configure it as below. Set person as a loop element and set class as a group element.
    Note: This feature requires the presence of a group element in the XML tree, otherwise an error displays below the name of the component in this window.
  6. Click root and then, click the plus button to add the sub-element class by selecting Create as sub-element.
  7. Repeat the procedure to add the sub-element person to class and to add the sub-elements id and name to person.
  8. Right-click class to open its contextual menu and click Add attribute to add the attribute class_id.
  9. Click the Auto map! button to link the input schema to the XML Tree:
  10. In the File Name field of the Basic settings, enter the file path to the XML file to generate, for example: "D:/out.xml".

Configuring the second subjob to append the existing XML file

Procedure

  1. Drop a second tFixedFlowInput and a second tAdvancedFileOutputXML from the Palette onto the design workspace. Connect the two components using a Row > Main link.
  2. Connect the first tFixedFlowInput to the second tAdvancedFileOutputXML with a Trigger > OnSubjobOk link.
  3. Double-click on tFixedFlowInput to display its Basic settings and select the Use Inline Content (delimited file). In the Content field, add the following information:
    1;1;item1
    1;2;item2
    2;1;item3
  4. Click the Edit Schema button and set the three-column schema.
  5. When prompted, click OK to accept the propagation or click afterward on the Sync columns button in the tJavaRow Basic settings view.
  6. Click the Configure its XML tree button to configure it as below. Follow the procedure used for the first subjob to set item as a loop element and set class as a group element.
  7. In the File Name field of the Basic settings, enter the file path to the XML file to generate, for example: "D:/out.xml".
  8. Execute the Job and check if the file "D:/out.xml" generated corresponds to the xml file presented at the beginning of this document. As expected, the xml source file is appended with various loop elements.