tXMLMap
Transforms and routes data from single or multiple sources to single or multiple
destinations.
tXMLMap is an advanced component
fine-tuned for transforming and routing XML data flow (data of the Document type), especially when processing numerous XML data
sources, with or without flat data to be joined.
tXMLMap Standard properties
These properties are used to configure tXMLMap running in the
Standard Job framework.
The Standard
tXMLMap component belongs to the Processing and the XML families.
The component in this framework is available in all Talend
products.
Basic settings
Map Editor |
It allows you to define the tXMLMap routing and transformation properties. |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at |
Keep order for document |
Select this check box to output XML elements strictly in the |
Global Variables
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
Possible uses are from a simple reorganization of fields to the When needs be, you can define sophisticated outputting strategy It is used as an intermediate component and fits perfectly the |
Limitation |
The limitations to be kept in mind are: – The use of this component supposes minimum Java and XML – This component is a junction step, and for this reason it – At least one loop element is required for each XML data flow |
The following sections present several generic use cases about how to
use the tXMLMap component, while if you need some
specific examples using this component along with the ESB components to build data services, see the scenarios for the
ESB components:
Mapping and transforming XML data
The following scenario creates a three-component Job that maps and
transforms data from an XML source file Customer.xml, and generates
an XML output flow which could be reused for various purposes, such as for an ESB
request, in the future based on the XML tree structure of the file Customer_State.xml.
These three components are:
-
tFileInputXML: provides the input data to
tXMLMap. -
tXMLMap: maps and transforms the received
XML data flows into one single XML data flow. -
tLogRow: displays the output data.
The content of the XML file Customer.xml is as
follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<?xml version="1.0" encoding="ISO-8859-15"?> <Customers> <Customer RegisterTime="2001-01-17 06:26:40.000"> <Name> <id>1</id> <CustomerName>Griffith Paving and Sealcoatin</CustomerName> </Name> <Address> <CustomerAddress>talend@apres91</CustomerAddress> <idState>2</idState> </Address> <Revenue> <Sum1>67852</Sum1> </Revenue> </Customer> <Customer RegisterTime="2002-06-07 09:40:00.000"> <Name> <id>2</id> <CustomerName>Bill's Dive Shop</CustomerName> </Name> <Address> <CustomerAddress>511 Maple Ave. Apt. 1B</CustomerAddress> <idState>3</idState> </Address> <Revenue> <Sum1>88792</Sum1> </Revenue> </Customer> <Customer RegisterTime="1987-02-23 17:33:20.000"> <Name> <id>3</id> <CustomerName>Glenn Oaks Office Supplies</CustomerName> </Name> <Address> <CustomerAddress>1859 Green Bay Rd.</CustomerAddress> <idState>2</idState> </Address> <Revenue> <Sum1>1225.</Sum1> </Revenue> </Customer> <Customer RegisterTime="1992-04-28 23:26:40.000"> <Name> <id>4</id> <CustomerName>DBN Bank</CustomerName> </Name> <Address> <CustomerAddress>456 Grossman Ln.</CustomerAddress> <idState>3</idState> </Address> <Revenue> <Sum1>64493</Sum1> </Revenue> </Customer> </Customers> |
follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="ISO-8859-15"?> <customers> <customer id="1"> <CustomerName>Griffith Paving and Sealcoatin</CustomerName> <CustomerAddress>talend@apres91</CustomerAddress> <idState>2</idState> </customer> <customer id="2"> <CustomerName>Bill's Dive Shop</CustomerName> <CustomerAddress>511 Maple Ave. Apt. 1B</CustomerAddress> <idState>3</idState> </customer> </customers> |
Adding and linking the components
-
Create a new Job and add a tFileInputXML
component, a tXMLMap component, a tLogRow component by typing their names in the design
workspace or dropping them from the Palette. -
Label the tFileInputXML component Customers to better identify its function.
Note:
A component used in the workspace can be labelled the way you need. For
further information about how to label a component, see
Talend Studio User Guide. -
Link the tFileInputXML component labelled
Customers to the tXMLMap component using a Row >
Main connection. -
Link the tXMLMap component to the tLogRow component using a Row > *New Output* (Main)
connection. In the pop-up dialog box, enter the name of the output connection,
Customer in this scenario.
Configuring the input flow
-
Double-click the tFileInputXML component labelled
Customers to open its Basic
settings view. -
Click the […] button next to Edit
schema and in the Schema
dialog box define the schema by adding one column Customer of Document
type.Note that the Document data type is essential
for making full use of tXMLMap. For further
information about this data type, see
Talend Studio User
Guide. -
Click OK to validate the changes and close the dialog
box. One row is added automatically to the Mapping table. -
In the File name/Stream field, browse to or type in
between double quotation marks the path to the XML source file that provides the
customer data. In this scenario, it is E:/Customer.xml. -
In the Loop XPath query field, type in an XPath
expression between double quotation marks to specify the node on which the loop
is based. In this scenario, it is /, which
means to perform look query from the root. -
In the XPath query column of the Mapping table, type in the fields to be queried between double
quotation marks. In this scenario, it is .,
which means all fields under the current node (root) will be extracted. -
In the Get Nodes column of the Mapping table, select the check box.
In order to build the Document type data
flow, it is necessary to get the nodes from this component.
Configuring tXMLMap for transformation
-
Double-click the tXMLMap component to open its Map Editor.
Note that the input area is already filled with the default basic XML
structure and the top table is the main input table. -
In the row1 input table, right-click the Customer node and from the contextual menu select
Import From File. In the pop-up dialog box,
browse to the XML source file to import therefrom the XML tree structure used by
the data to be received by tXMLMap. In this
scenario, the XML source file is Customer.xml, which is the
input data to the tFileInputXML component
labelled Customers.Note:You can also import an XML tree from an XSD file. When importing either an
input or an output XML tree structure from an XSD file, you can choose an
element as the root of your XML tree. For more information on importing an
XML tree structure from an XSD file, see
Talend Studio
User Guide. -
In the imported XML tree, right-click the Customer node
and from the contextual menu select As loop
element to set it as the loop element. -
On the lower part of this map editor, click the Schema
editor tab to display the corresponding view. Then on the right
side of this view, add one column Customer_States of
Document type to the
Customer schema table. The corresponding XML root is
added automatically to the Customer output
table on the top right side which represents the output flow. -
In the Customer output table, right-click the Customer_States node and from the contextual menu select
Import From File. In the pop-up dialog box,
browse to the XML file from which the XML tree structure is imported. In this
scenario, it is Customer_State.xml. -
Right-click the customer node and from the contextual
menu select As loop element to set it as the
loop element. -
In the row1 input table, click the
id node and drop it to the Expression column in the row of the @id node in the Customer
output table.Do the same to map CustomerName to
CustomerName, CustomerAddress to
CustomerAddress, and idState to
idState from the input table to the output
table.Note:In some circumstances, you may have to keep empty elements in your output XML tree. If
so, you can use tXMLMap to manage them. For
further information about how to manage empty elements using tXMLMap, see
Talend Studio
User Guide. -
On the top of the Customer output table,
click the wrench icon and set the value of the All in
one property to true to generate
a single XML flow. For further information about the All
in one feature, see
Talend Studio User
Guide. -
Click OK to validate the changes and close
the Map Editor.Note:If you close the Map Editor without having set the
required loop elements as described earlier in this scenario, the root
element will be automatically set as the loop element.
Configuring tLogRow to display the customer information
- Double-click the tLogRow component to open its Basic settings view.
-
Click the Sync columns button to retrieve the
schema from its preceding component.
Saving and executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 to execute the Job.
As shown above, the transformed customer information is displayed on the
console.
Launching a lookup flow to join complementary data
Based on the previous scenario, this scenario shows how to use a lookup flow to
join data of interest in the XML file USState.xml to the main flow.
Another tFileInputXML component is added to the Job to
load data from the lookup file USState.xml to the processing component
tXMLMap.
The content of the XML file USState.xml is as
follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?xml version="1.0" encoding="ISO-8859-15"?> <USStates> <States> <idState>1</idState> <LabelState>Alabama</LabelState> </States> <States> <idState>2</idState> <LabelState>Connecticut</LabelState> </States> <States> <idState>3</idState> <LabelState>Ohio</LabelState> </States> <States> <idState>4</idState> <LabelState>Wyoming</LabelState> </States> <States> <idState>5</idState> <LabelState>Hawaii</LabelState> </States> </USStates> |
Adding and linking another input component
-
In your Studio, open the Job used in the previous scenario to display it in
the design workspace. -
Add another tFileInputXML component to the Job by typing
its name in the design workspace or dropping it from the Palette. Label the component USStates to better identify its function. -
Link the tFileInputXML component labelled USStates to the tXMLMap component using a Row >
Main connection, and the connection is
automatically changed to a lookup flow.
Configuring the input flow for lookup
-
Double-click the tFileInputXML component labelled
USStates to open its Basic
settings view. -
Click the […] button next to Edit
schema and in the Schema
dialog box define the schema by adding one column USState of Document
type. -
Click OK to validate the changes and close the dialog
box. One row is added automatically to the Mapping table. -
In the File name/Stream field, browse to or type in
between double quotation marks the path to the XML source file that holds the
complementary data. In this scenario, it is
E:/USState.xml. -
In the Loop XPath query field, type in an XPath
expression between double quotation marks to specify the node on which the loop
is based. In this scenario, it is /, which
means to perform look query from the root. -
In the XPath query column of the Mapping table, type in the fields to be queried between double
quotation marks. In this scenario, it is .,
which means all fields under the current node (root) will be extracted. -
In the Get Nodes column of the Mapping table, select the check box. This retrieves
the XML structure for the Document type
data.
Configuring tXMLMap for transformation
-
Double-click the tXMLMap component to open its Map Editor.
Note that the input area is already filled with the defined input tables and
the top table is the main input table. -
In the row2 input table, right-click the
USState node and from the contextual menu
select Import From File. In the pop-up dialog
box, browse to the XML source file to import therefrom the XML tree structure
used by the data to be received by tXMLMap. In
this scenario, the XML source file is USState.xml, which is the input data to tFileInputXML labelled USStates. -
In the imported XML tree, right-click the States node and from the contextual menu select As loop element to set it as the loop element.
-
In the row1 main input table, click the
idState node and drop it to the Exp.key column in the row of the idState
node in the row2 lookup input table. This
creates a join between the two input tables on the idState
data, among which the idState node from the main flow
provides the lookup key. -
In the row2 lookup input table, click the
LabelState node and drop it on the
customer node in the Customer output table. A dialog box pops up. -
In the pop-up dialog box, select Create as sub-element
of target node and click OK. A
new LabelState sub-element is added to the
output XML tree and mapped with the LabelState node in the
lookup input table. -
Click OK to validate the mappings and close
the Map Editor.
Saving and executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 to run the Job.
As shown above, the state names from the lookup file with the state IDs matching those in
the main input file are added to the data flow and the combined information is
displayed on the console.
A step-by-step tutorial related to this Join topic is available on the Talend
Technical Community Site. For further information, see http://talendforge.org/tutorials/tutorial.php?language=english&idTuto=101.
Mapping data using a filter
Based on Launching a lookup flow to join complementary data, this scenario presents how to apply filter
condition(s) to select the data of interest using tXMLMap.
Mapping data using a filter
-
In your Studio, open the Job used in the previous scenario to display it in the
design workspace. -
Double-click the tXMLMap component to open its Map Editor.
-
On the top of the Customer output table, click
thebutton to open the filter area.
-
Drop the idState node in the main input table to the filter
area. The XPath [row1.Customer:/Customers/Customer/Address/idState] of the
idState node is added automatically to this filter
area.Enter == 2 after the XPath of the idState node, and the complete filter condition becomes
[row1.Customer:/Customers/Customer/Address/idState] ==
2. This means only the customer data with the state id of 2 will be passed to the output flow. -
Click OK to validate the changes and close the
map editor. - Press Ctrl + S to save the Job and then F6 to run the Job.
As shown above, the customers Griffith Paving and Sealcoatin and
Glenn Oaks Office Supplies, whose state id is
2 are displayed on the console.
Catching the data rejected by lookup and filter
The data rejected by the lookup and filter conditions set in tXMLMap can be caught and outputted by this component itself.
Based on Mapping data using a filter, this scenario presents how to catch the data rejected
by the lookup and the filter set up in the previous scenarios. Another tLogRow component is added to the Job used in the previous scenario to
display the rejected data.
Adding and linking another output component
-
In your Studio, open the Job used in the previous scenario to display it in
the design workspace. -
Add another tLogRow component to the Job by typing its
name in the design workspace or dropping it from the Palette. -
Link the tXMLMap component to the second tLogRow using a Row
> *New Output* (Main) connection. In the pop-up
dialog box, enter the name of the output connection, Reject in this example.
Configuring tXMLMap for transformation
-
Double-click the tXMLMap component to open its Map Editor. An empty Reject
output table that carries the rejected data has been added to the output side to
represent the output data flow carrying the rejected data. -
In the row1 main input table, click the
id node and drop it on the Reject output table. A column id is added to the Reject schema table in the Schema
editor on the lower part of the map editor. -
Do the same to drop CustomerName, CustomerAddress, and idState in the row1 main
input table and LabelState in the row2 lookup input table on the Reject output table. Another four columns CustomerName, CustomerAddress, idState, and
LabelState are added to the Reject schema table in the Schema editor.Note:In this scenario, the Reject output flow uses the
flat data type. However, you can create an XML tree view for this flow
similar to the Customer output flow using
the Document data type. For further
information about how to use the Document
type, see Mapping and transforming XML data. -
On the top of the Reject output table,
click thebutton to open the property setting area.
-
Set the value of the Catch Output Reject
property to true to catch the data rejected by
the filter set up in the previous scenario for the Customer
output flow. -
Set the value of the Catch Lookup Inner Join
Reject property to true to catch
the data rejected by the inner join operation. -
Click OK to validate the changes and close
the map editor.
Configuring the output flow
-
Double-click the second tLogRow component to open its
Basic settings view. -
Click the Sync columns button to retrieve the
schema from its preceding component. -
In the Mode area, select Table (print values in cells of a table) for better
readability of the result.
Saving and executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 to run the Job.
The captured data rejected by the filter and the lookup reads as follows in
the Run view:As shown above, the data whose idState
value is 2 is selected by the filter set up
in the previous scenario and displayed in the upper part, and the data whose
idState value is not 2 is rejected and displayed in the lower
part.
Mapping data using a group element
Based on Launching a lookup flow to join complementary data, this scenario presents how to set up an element as group
element in the Map Editor of
tXMLMap to group the output data. For more
information about how to group the output data using tXMLMap, see
Talend Studio User Guide.
The objective of this scenario is to group the customer id and the
customer name information according to the states the customers come from. You need to
reconstruct the XML tree view of the Customer output table by
considering the following factors:
-
The elements tagging the customer id and the customer name
information should be located under the loop element. Thus they are the
sub-elements of the loop element. -
The loop element and its sub-elements should be dependent directly
on the group element. -
The element tagging the state information used as the grouping
condition should be dependent directly on the group element. -
The group element cannot be the root element.
Based on this analysis, the XML structure of the output data should read
as follows. The customers node is the root element, the customer node is set as the group element and the output data is
grouped according to the LabelState element.
To put a group element into effect, the XML data to be processed should
have been sorted, for example via your XML tools, around the element that will be used
as the grouping condition. In this example, the customers possessing the same state id
should be put together. The input data in the XML file Customer.xml should read as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?xml version="1.0" encoding="ISO-8859-15"?> <Customers> <Customer RegisterTime="2001-01-17 06:26:40.000"> <Name> <id>1</id> <CustomerName>Griffith Paving and Sealcoatin</CustomerName> </Name> <Address> <CustomerAddress>talend@apres91</CustomerAddress> <idState>2</idState> </Address> <Revenue> <Sum1>67852</Sum1> </Revenue> </Customer> <Customer RegisterTime="1987-02-23 17:33:20.000"> <Name> <id>3</id> <CustomerName>Glenn Oaks Office Supplies</CustomerName> </Name> <Address> <CustomerAddress>1859 Green Bay Rd.</CustomerAddress> <idState>2</idState> </Address> <Revenue> <Sum1>1225.</Sum1> </Revenue> </Customer> <Customer RegisterTime="2002-06-07 09:40:00.000"> <Name> <id>2</id> <CustomerName>Bill's Dive Shop</CustomerName> </Name> <Address> <CustomerAddress>511 Maple Ave. Apt. 1B</CustomerAddress> <idState>3</idState> </Address> <Revenue> <Sum1>88792</Sum1> </Revenue> </Customer> <Customer RegisterTime="1992-04-28 23:26:40.000"> <Name> <id>4</id> <CustomerName>DBN Bank</CustomerName> </Name> <Address> <CustomerAddress>456 Grossman Ln.</CustomerAddress> <idState>3</idState> </Address> <Revenue> <Sum1>64493</Sum1> </Revenue> </Customer> </Customers> |
Mapping data using a group element
- In your Studio, open the Job used in Launching a lookup flow to join complementary data to display it in the design workspace, and double-click the tXMLMap component to open its Map Editor.
-
In the XML tree view of the Customer output table,
right-click the customer (loop) node and select
Delete from the contextual menu. Thus
all of the elements under the customers root node are
removed, then you can reconstruct the XML tree view that can be used to group
the output data of interest. -
Right-click the customers root node and select
Create Sub-Element from the
contextual menu. In the pop-up dialog box, enter the name of the new
sub-element. In this example, it is customer. -
Click OK to validate the changes and
close the dialog box. A customer node is added under the
customers root node in the output table. -
In the row2 lookup input table, select the LabelState node and drop it onto the customer node in the output table. In the pop-up dialog box, select
Create as sub-element of target node
and click OK to close the dialog box. A
LabelState node is added under the customer node in the output table. -
Right-click the customer node in the output table and
select Create Sub-Element from the
contextual menu. In the pop-up dialog box, enter the name of the new
sub-element. In this example, it is Name. -
Click OK to validate the changes and
close the dialog box. A Name node is added under the customer node in the output table. -
In the row1 main input table, select the id and CustomerName nodes and
drop them onto the Name node in the output table. In the
pop-up dialog box, select Create as sub-element of
target node and click OK
to close the dialog box. A id node and a CustomerName node are added under the Name node in the output table. -
In the output table, right-click the Name node and from
the contextual menu select As loop
element to set it as the loop element, then right-click the customer node and from the contextual menu select
As group element to group the output
data according to the LabelState element. -
Click OK to validate the changes and
close the map editor. -
Press Ctrl+S to save the Job and then
F6 to run the Job.
As shown above, the id element and the CustomerName
element contained in the loop are grouped according to the LabelState element. The group element customer tags
the start and the end of each group.
Classifying the output data with aggregate element
Based on the previous scenarios , this scenario presents how to set up an
element as aggregate element in the Map Editor of tXMLMap
to classify the output data into separate XML flows. For more information about how to
aggregate the output data using tXMLMap, see Talend Studio User Guide.
The objective of this scenario is to classify the customer id and the customer name
information using an aggregate element in accordance with the states they come from and then
to send these classes separately in different XML flows to the next component.
To put an aggregate element into effect, the XML data to be processed should have been
sorted, for example via your XML tools, around the element that will be used as the
aggregating condition. In this example, the customers possessing the same state id should be
put together. The input data in the XML file Customer.xml
should be same as the input data in .
Classifying the output data with aggregate element
-
In your Studio, open the Job used in , and double-click
the tXMLMap component to open its Map Editor. -
Right-click the customer element in the output table and
select Remove group element from the contextual
menu. -
On the top of the output table, click the wrench icon and set the value of the
All in one property to false. -
Right-click the LabelState element and select
As aggregate element from the contextual menu.
The LabelState element tags the state information
of each customer and the customer information will be classified according to the
state information.To make the aggregate element available, ensure that the value of the
All in one property is set to false. For further information about the All in one feature, see
Talend Studio User Guide. -
Click OK to validate the changes and close the
Map Editor. - Press Ctrl+S to save the Job and then F6 to run the Job.
As shown above, tXMLMap outputs two separate XML flows,
each of which carries the information of one state and the customers from that state.
Restructuring products data using multiple loop elements
The following scenario creates a four-component Job that restructures the products data
from an XML source file ProductsIn.xml using multiple
loop elements.
These four components are:
-
tFileInputXML: reads the source products data and passes
it to the tXMLMap component. -
tXMLMap: transforms the input flow to the
expected structure streamlined. -
tLogRow: presents the execution result on the
console. -
tFileOutputXML: writes the output flow into an XML
file.
The content of the source XML file ProductsIn.xml is as
follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version="1.0" encoding="ISO-8859-15"?> <products category="1" name="laptop"> <!-- Summary --> <summary> <company>DELL, HP</company> <sales unit="Dollars">12345678910.12345</sales> <model>business</model> </summary> <!-- Loop1 manufacture --> <manufacture id="manu_1" date="2012-10-30"> <name>DELL</name> </manufacture> <manufacture id="manu_2" date="2012-10-28"> <name>HP</name> </manufacture> <!-- Loop2 types --> <types model="business1"> <type>DELL123</type> <manufacture_id>manu_1</manufacture_id> </types> <types model="business2"> <type>HP123</type> <manufacture_id>manu_2</manufacture_id> </types> <!-- Loop3 sale --> <sales> <sale unit="Dollars" type="DELL123"> <quater>1</quater> <income>12345</income> </sale> <sale unit="Dollars" type="HP123"> <quater>1</quater> <income>12345.123</income> </sale> </sales> </products> |
The objective of this scenario is to restructure the products data to streamline the
presentation of the products information to serve the manufacturing operations. The expected
output data is as follows. The root element is changed to manufacturers, the sales information is consolidated into the sale element, and the manufacturer element is reduced to one single level.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="ISO-8859-15"?> <manufacturers category="1" name="laptop"> <sales unit="Dollars"> <sale sales_type="DELL123">12345.0</sale> <sale sales_type="HP123">12345.123</sale> </sales> <manufacturer id="manu_1" date="03-04-0036" name="DELL"/> <manufacturer id="manu_2" date="04-04-0034" name="HP"/> <types> <type>DELL123</type> <manufacturer_id>manu_1</manufacturer_id> </types> <types> <type>DELL123</type> <manufacturer_id>manu_2</manufacturer_id> </types> <types> <type>HP123</type> <manufacturer_id>manu_1</manufacturer_id> </types> <types> <type>HP123</type> <manufacturer_id>manu_2</manufacturer_id> </types> </manufacturers> |
Adding and linking the components
-
Create a new Job and add a tFileInputXML
component, a tXMLMap component, a tLogRow component, and a tFileOutputXML component by typing their names in the design
workspace or dropping them from the Palette. -
Link the tFileInputXML component to the tXMLMap component using a Row > Main
connection. -
Link the tXMLMap component to the tLogRow component using a Row
> *New Output* (Main) connection. In the
pop-up dialog box, enter the name of the output connection,
outDoc in this example. -
Link the tLogRow component to the tFileOutputXML component using a Row > Main
connection.
Configuring the input flow
-
Double-click the tFileInputXML component to open its
Basic settings view. -
Click the […] button next to Edit
schema and in the Schema
dialog box define the schema by adding one column doc of Document type. -
Click OK to validate the changes and close the dialog
box. One row is added automatically to the Mapping table. -
In the File name/Stream field, browse to or type in
between double quotation marks the path to the XML source file that provides the
products data. In this scenario, it is E:/ProductsIn.xml. -
In the Loop XPath query field, type in an XPath
expression between double quotation marks to specify the node on which the loop
is based. In this scenario, it is /, which
means to perform look query from the root. -
In the XPath query column of the Mapping table, type in the fields to be queried between double
quotation marks. In this scenario, it is .,
which means all fields under the current node (root) will be extracted. - In the Get Nodes column of the Mapping table, select the check box.
Configuring tXMLMap with multiple loops
-
Double-click the tXMLMap component to open its Map Editor.
Note that the input area is already filled with the default basic XML
structure and the top table is the main input table. -
In the row1 input table, right-click the doc node and from the contextual menu select
Import From File. In the pop-up dialog box,
browse to the XML source file to import therefrom the XML structure used by the
data to be received by tXMLMap. In this
scenario, the XML source file is ProductsIn.xml, which contains the input data to tFileInputXML. -
In the imported XML tree, right-click the manufacturer node and from the contextual menu select As loop element to set it as the loop element. Then
do the same to set the types node and the
sale node as loop elements
respectively. -
On the lower part of the map editor, click the Schema
editor tab to display the corresponding view. Then on the right
side of this view, add one column outDoc of
Document type to the schema table. The
corresponding XML root is added automatically to the output table on the top
right side which represents the output flow. -
In the outDoc output table, import the XML data
structure to be used from the XML file that contains the expected output data
and provides the expected XML structure.Right-click the sale node in the output
table and select As loop element from the
contextual menu. Then do the same to set the manufacturer node and the types node as loop elements respectively. -
In the row1 input table, click the @category node and drop it to the Expression field of the @category node in the outDoc
output table.Do the same to map other nodes from the input table to the output
table:-
the @name node to the @name node,
-
the @unit node under the summary node to the @unit
node, -
the @id node to the @id node and to the manufacturer_id node respectively,
-
the @date node to the @date node,
-
the name node to the @name node,
-
the type node to the type node,
-
the @type node to the @sales_type node, and
-
the income node to the sale (loop) node.
-
-
On the top of the outDoc output table,
click the wrench icon and set the value of the All in
one property to true to generate
a single XML flow. For further information about the All
in one feature, see
Talend Studio User
Guide. -
Click the […] button next to the manufacturer loop element and in the pop-up
Configure source loops dialog box click
the [+] button to add one source loop manufacturer. Do the same to add one source loop
sale for the sale loop element. -
Click the […] button next to the types loop element and in the pop-up Configure source loops dialog box add two source
loops types and manufacturer. Make sure the sequence number of the types source loop is 0 so that the relative part of the output flow will be sorted
based on the values of the type
element.Note:When a loop element receives mappings from more than one loop element of
the input flow, it allows you to set the sequence of the input loops. For
example, the types loop element of the
output flow in this scenario is mapped with the @id node which belongs to the manufacturer loop element and the type node which belongs to the types loop element of the input flow. The output flow will
be sorted according to the primary types
loop. -
Click OK to validate the mappings and close
the Map Editor.
Configuring the output flow
- Double-click the tLogRow component to open its Basic settings view.
-
Click the Sync columns button to retrieve the
schema from its preceding component and accept the propagation prompted by the
pop-up dialog box. -
Double-click the tFileOutputXML component to open its
Basic settings view. -
In the File Name field, browse to or enter the path to
the file in which the output data will be written. In this scenario, it is
E:/ProductsOut.xml. -
Select the Incoming record is a document
check box.
Saving and executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 to execute the Job.
As shown above, the input products data is restructured as expected and the output data is
displayed on the console and written into the XML file ProductsOut.xml.