August 17, 2023

tXMLMap – Docs for ESB 5.x

tXMLMap

txmlmap_icon32_white.png

tXMLMap properties

Component family

Processing/XML

 

Function

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.

Purpose

tXMLMap transforms and routes
data from single or multiple sources to single or multiple
destinations.

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 the
Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio
User Guide.

Usage

Possible uses are from a simple reorganization of fields to the
most complex jobs of data multiplexing or demultiplexing
transformation, concatenation, inversion, filtering and so on.

When needs be, you can define sophisticated outputting strategy
for the output XML flows using group element, aggregate element,
empty element and many other features such as All in one. For further information about these
features, see Talend Studio User
Guide
.

It is used as an intermediate component and fits perfectly the
process requiring many XML data sources, such as, the ESB
request-response processes.

Log4j

The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User
Guide
.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

The limitations to be kept in mind are:

– The use of this component supposes minimum Java and XML
knowledge in order to fully exploit its functionalities.

– This component is a junction step, and for this reason it
cannot be a start nor an end component in the Job.

– At least one loop element is required for each XML data flow
involved.

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:

If you need further information about the principles of mapping multiple input and
output flows, see Talend Studio User
Guide
.

Scenario 1: Mapping and transforming XML data

In this scenario, a three-component Job is run to map and transform data from one XML
source file customer.xml, and generate an XML output flow which
could be reused for various purposes in the future, such as for an ESB request.

These three components are:

  • tFileInputXML: this component is used to
    provide input data to tXMLMap.

  • tXMLMap: this component maps and transforms
    the received XML data flows into one single XML data flow.

  • tLogRow: this component is used to display
    the output data.

Use_Case_tXMLMapBasicJob.png

To replicate this scenario, proceed as the following sections illustrate.

Dropping and linking the components

To do this, proceed as follows:

  1. From the Palette, drop tFileInputXML, tXMLMap and tLogRow into
    the Design workspace.

    Note

    A component used in the workspace can be labelled the way you need. In
    this scenario, this input component is labelled
    Customers for tFileInputXML. For further information about how to
    label a component, see Talend Studio User
    Guide
    .

  2. Right-click the tFileInputXML component
    labelled Customers to open its contextual menu.

  3. From this menu, select Row
    >
    Main link to connect this component to
    tXMLMap.

  4. Repeat this operation to connect tXMLMap
    to tLogRow using Row > *New Output*
    (Main)
    link. A pop-up dialog box prompts you to name this
    output link. In this scenario, name it as
    Customer.

    Use_Case_tXMLMap8.png

Then you can continue to configure each component.

Configuring the input flow

To do this, proceed as follows:

  1. Double-click the tFileInputXML component
    labelled Customers to display its Basic settings view.

    Use_Case_tXMLMap2.png
  2. Next to Edit schema, click the three-dot
    button to open the schema editor.

    Use_Case_tXMLMap3.png
  3. In the schema editor, click the plus button to add one row.

  4. In the Column column, type in a new name
    for this row. In this scenario, it is Customer.

  5. In the Type column, select the data type
    of this row. In this scenario, it is Document. The
    document data type is essential for making full use of tXMLMap. For further information about this data type, see
    Talend Studio User
    Guide
    .

  6. Click OK to validate this editing. One
    row is added automatically to the Mapping
    table.

  7. In the File name/Stream field, browse to
    or type in the path to the XML source that provides the customer data. In
    this scenario, it is “E:/Studio/Customer.xml”.

  8. In the Loop XPath query field, type in
    "/" to replace the default one. This means the source data
    is queried from the root.

  9. In the XPath query column of the
    Mapping table, type in the XPath. In
    this scenario, type in ".", meaning that all of the data from
    source are queried.

  10. In the Get Nodes column of the Mapping table, select the check box.

    Note

    In order to build the Document type
    data flow, it is necessary to get the nodes from this component.

Configuring tXMLMap for transformation

To do this, proceed as follows:

  1. Double-click the tXMLMap component to
    open the Map Editor.

    Note that the input area is already filled with the defined input tables
    and that the top table is the main input table.

  2. In the left table, right-click Customer
    to open the contextual menu.

    Use_Case_tXMLMap5.png
  3. From this contextual menu, select Import From
    File
    and in the pop-up dialog box, browse to the
    corresponding source file in order to import therefrom the XML structure
    used by the data to be received by tXMLMap.
    In this scenario, the source file is Customer.xml,
    which is the data input to tFileInputXML
    (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 from an XSD file, see Talend Studio User Guide.

  4. In the imported XML tree, right-click the Customer
    node and select As loop element to set it
    as the loop element.

    Use_Case_tXMLMap7.png
  5. On the lower part of this map editor, click the Schema editor tab to display the corresponding view.

  6. On the right side of this view, click the plus button to add one row to
    the Customer table and rename this row as
    Customer_States.

    Use_Case_tXMLMap11.png
  7. In the Type column of this
    Customer_States row, select Document as the data type. The corresponding XML root is
    added automatically to the top table on the right side which represents the
    output flow.

    Use_Case_tXMLMap12.png
  8. On the right side in the top table labelled Customer,
    import the XML data structure that you need to use from the corresponding
    XML source file. In this scenario, it is
    Customer_State.xml.

    Use_Case_tXMLMap9.png
  9. Right-click the customer node and select As loop element from the contextual menu.

    Then you can begin to map the input flow to the output flow.

  10. In the top table on the input side (left) of the map editor, click
    the id node and drop it to the Expression column in the row corresponding to the
    output row you need map. In this scenario, it is the
    @id node.

    Use_Case_tXMLMapBasicMap.png
  11. Do the same to map CustomerName to
    CustomerName, CustomerAddress
    to CustomerAddress and idState to
    idState from the left side to the right
    side.

    Note

    In the real project, 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.

  12. If required to generate single XML flow, click the wrench icon on top of
    the output side to open the setting panel and set the All in one feature as true.
    In this example, this option is set as true. For further information about the All in one feature, see Talend Studio
    User Guide
    .

    use_case-txmlmap_all_in_one.png
  13. Click OK to validate the mappings 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 loop
    element.

    Then you can run this Job.

Configuring tLogRow to display the customer information

  1. Double-click the tLogRow component to
    open its Basic settings view.

  2. Click Sync columns button to retrieve the
    schema from its preceding component.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to execute the Job.

    Use_Case_tXMLMapBasicExecution.png

    The customer information transformed will be displayed on the
    console.

Scenario 2: Launching a lookup in a second XML flow to join complementary
data

Based on the previous scenario, this scenario shows how to use lookup in an XML flow
to join the data of interest to a given XML flow. The XML data for lookup is held in the
USStates.xml file.

To do this, another tFileInputXML component is added
to the previous Job in order to load and send the complementary data to tXMLMap. Thus this Job looks like as follows:

Use_Case_tXMLMap1.png

To replicate this scenario, proceed as the following sections illustrate.

Configuring the data flow for lookup

To do this, proceed as follows:

  1. From the Palette, drop tFileInputXML into the Design workspace.

    Note

    A component used in the workspace can be labelled the way you need. In
    this scenario, the newly added tFileInputXML is labelled USstates.
    For further information about how to label a component, see Talend Studio User Guide.

  2. Double-click the tFileInputXML component
    labelled USStates to open its contextual menu and
    select Row > Main connection to connect this component to tXMLMap. As you create this connection in the
    second place, this connection is of type Lookup.

  3. Double-click the tFileInputXML component
    labelled USStates to open its Basic settings view.

    Use_Case_tXMLMap4.png
  4. Next to Edit schema, click the three-dot
    button to open the schema editor.

  5. Click the plus button to add one row and rename it to
    USState.

  6. In the Type column, select the Document option from the drop-down list.

    Use_Case_tXMLMap13.png
  7. Click OK to validate this editing.

  8. In the File name/Stream field, browse to
    or type in the path to the USStates.xml file.

    Note

    The input schemas could be stored in the Metadata node of the Repository tree view for easy retrieval. For further
    information regarding metadata creation in the Repository, see Talend Studio User Guide.

  9. In the Loop XPath query field, type in
    "/" to replace the default value. This means the loop is
    based on the root.

  10. In the Mapping table, where one row is
    already added automatically, enter "." in the XPath query column to retrieve US States data
    from the source file.

  11. In the Get Nodes column, select the check
    box. This retrieves the XML structure for the Document type data.

Configuring the transformation

To do this, proceed as follows:

  1. Double-click the tXMLMap component to
    open the Map Editor.

    Note that the input area is already filled with the defined input tables
    and that the top table is the main input table.

  2. Right-click USState in the lookup input
    table to open its contextual menu.

    components-use_case-txmlmap-import_usstate.png
  3. From the contextual menu, select Import From
    File
    and in the pop-up dialog box, browse to the
    corresponding source file in order to import therefrom the XML structure
    used by the data to be received by tXMLMap.
    In this scenario, the source file is USStates.xml, which is the data input of the tFileInputXML component labelled USStates.

  4. Right-click the States node and select
    As loop element from the contextual
    menu.

    components-use_case-txmlmap-states_as_loop.png
  5. In the main input table, click the idState node and
    drop it, in the lookup input table, to the Exp.key column in the row corresponding to the
    idState row. This creates a join between the two
    tables on the idState data, among which the
    idState node from the main flow provides the lookup
    key.

    Use_Case_tXMLMap6.png

    Then you can begin to modify the mapping you have done in the previous
    scenario to join the complementary data into the input flow. This mapping
    then should look like as follows:

    Use_Case_tXMLMap10b.png
  6. In the lookup table on the input side
    (left) of the map editor, click the LabelState row and
    drop it on the customer node on the output side. A
    dialog box pops up.

    Use_Case_tXMLMap14.png
  7. In this dialog box, select Create as sub-element of
    target node
    and click OK.
    This operation adds a new sub-element to the output XML tree and maps it
    with LabelState on the input inside at the same
    time.

  8. If required to generate single XML flow, click the wrench icon on top of
    the output side to open the setting panel and set the All in one feature as true.
    In this example, this option is set as true. For further information about the All in one feature, see Talend Studio
    User Guide
    .

    use_case-txmlmap_all_in_one.png
  9. Click OK to validate the mappings and
    close the Map Editor.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to run this Job.

    The Run view presents the execution
    result which may read as follows:

    Use_Case_tXMLMap15.png

    The US state labels that correspond to the state IDs provided as the
    lookup key by the main data flow are selected and outputted.

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.

Scenario 3: Mapping data using a filter

Based on Scenario 2: Launching a lookup in a second XML flow to join complementary
data
, this scenario presents how to apply filter
condition(s) to select the data of interest using tXMLMap.

For example, you need to select the customer data where the state id is
9.

To replicate this scenario, proceed as follows:

  1. In your Studio, open the Job used in the previous scenario to display it in
    the Design workspace.

    Use_Case_tXMLMap1.png
  2. Double-click tXMLMap to open its editor. In
    this editor, the input and output data flows have been mapped since the
    replication of the previous scenario.

    Use_Case_tXMLMap10b.png
  3. On the output side (right), click the Expression_Filter.png button to open the filter area.

    Use_Case_tXMLMapFilter1.png
  4. In this filter area, drop the idState node from the tree
    view of the input data flow. The Xpath of idState is added
    automatically to this filter area.

  5. Still in this area, write down the filter condition of interest in Java. In
    this scenario, this condition reads:
    "9".equals([row1.Customer:/Customers/Customer/Address/idState])

  6. If required to generate single XML flow, click the wrench icon on top of the
    output side to open the setting panel and set the All in
    one
    feature as true. In this
    example, this option is set as true. For
    further information about the All in one
    feature, see Talend Studio User
    Guide
    .

    use_case-txmlmap_all_in_one.png
  7. Click OK to validate this editing and close
    this editor.

  8. Press F6 to run this Job.

    The execution result is displayed in the Run
    view as follows:

    Use_Case_tXMLMapFilter2.png

    The result says that the customer Pivot Point College is
    selected as its state ID is 9, representing the
    Florida state in this scenario.

Scenario 4: Catching the data rejected by lookup and filter

The data rejected by the lookup and filter conditions you set in tXMLMap can be caught and outputted by this component itself.

Based on Scenario 3: 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 sections.

In this scenario, another tLogRow component is added
to the Job used in the previous scenario and thus the Job displays as follows:

Use_Case_tXMLMapReject1.png

To replicate this scenario, proceed as follows:

  1. In your Studio, open the Job used in the previous scenario to display it in
    the Design workspace.

  2. From the Palette, drop the tLogRow component on the workspace.

  3. Right-click tXMLMap to open its contextual
    menu and select Row > *New Output* (Main) to
    connect this component to the newly added tLogRow component. A dialog box pops up to prompt you to name
    this output link. In this scenario, name it as
    Reject.

    Use_Case_tXMLMapReject2.png
  4. Click OK to validate this creation.

  5. Double click the tXMLMap component to open
    its editor. An empty Reject table has been added to the
    output side to represent the output data flow carrying the rejected data. You
    need to complete this table to make this editor look like as follows:

    Use_Case_tXMLMapReject3.png
  6. Select this empty Reject table.

  7. In the lower part of this editor, click the Schema
    editor
    tab to open the corresponding view.

  8. On the right part of this Schema editor view,
    click the plus button to add the rows you need to use. In this scenario, click
    four times to add four rows to the Reject table.

    Use_Case_tXMLMapReject4.png
  9. In the Reject table presented on the right part of this
    Schema editor view, rename each of the four
    newly added rows. They are: ID,
    Customer, idState,
    LabelState.

    Note

    In this scenario, the Reject output flow uses flat
    data type. However, you can create an XML tree view for this flow using the
    Document data type. For further
    information about how to use this Document
    type, see Scenario 1: Mapping and transforming XML data.

    The Reject table is completed and thus you have defined
    the schema of the output flow used to carry the captured rejected data. Then you
    need to map the data flow and set up the condition(s) to catch the rejected data
    of interest.

Configuring the mapping and running the Job

  1. In the main input table on the left side of the map editor, drag and drop
    the id node to the Expression column of the corresponding row in the Reject output table.

  2. Do the same to drag and drop CustomerName, CustomerAddress, idState
    in the main input table, and LabelState
    in the lookup input table to the corresponding row in the Reject output table.

  3. On the upper part of the output side in this Map
    editor
    , select the Reject table.

  4. At the top of this table, click the Map_setting.png button to open the setting area.

    Use_Case_tXMLMapReject5.png
  5. In the Catch Output Reject row of the
    setting area, select true from the
    drop-down list. Thus tXMLMap outputs the
    data rejected by the filter set up in the previous scenario for the
    Customer output flow.

  6. Do the same thing to switch the Catch Lookup Inner
    Join Reject
    row to the true
    option.

  7. Click OK to validate this editing and
    close this editor.

  8. Double-click the second tLogRow component
    to open its Basic settings view.

  9. Click Sync columns button to retrieve the
    schema from its preceding component.

  10. Press F6 to run this Job.

    The captured data rejected by the filter and the lookup reads as follows
    in the Run view:

    Use_Case_tXMLMapReject6.png

    None of the State IDs of these customers is 9. The
    customer BBQ Smith’s Tex Mex is marked with the state
    ID 60. This number does not exist in the
    idState column of USStates.xml
    where the defined lookup was none, so the data of this customer is rejected
    by the lookup and the other data rejected by the filter.

    The data selected by the filter you set up in the previous scenario reads
    as follows in XML format.

    Use_Case_tXMLMapReject7.png

Scenario 5: Mapping data using a group element

Based on the Job used in Scenario 2: Launching a lookup in a second XML 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.

Use_Case_tXMLMap1.png

To replicate this scenario, you can reuse the Job in Scenario 2: Launching a lookup in a second XML flow to join complementary
data
.

In this Job, double-click tXMLMap to open the
Map editor.

Use_Case_tXMLMap10b.png

The objective of this scenario is to group the customer id and the customer name
information according to the States the customers come from. To do this, you need to
adjust the XML structure with 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 States used as grouping condition should be dependent
    directly on the group element.

  • The group element cannot be the root element.

Note

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 you need to use as the
grouping condition. The figure below presents part of the sorted source data used in
this scenario. The customers possessing the same State id is already put
together.

use_case-txmlmap-sorted_source.png

Based on this analysis, the structure of the output data should read as
follows:

Use_Case_tXMLMapGroup1.png

In this figure, the customers node is the root, the
Customer element is set as group
element
and the output data is grouped according to the
LabelState element.

Note

To set a group element, two restrictions must be respected:

  • the root node cannot be set as group
    element
    ;

  • the group element must be the parent
    of the loop element.

Once the group element is set, the first element except the loop one is used as
condition to group the output data.

To perform the adjustment according to this analysis, proceed as follows:

  1. In the XML tree view of the output side, right-click the customer
    (loop)
    node to open the contextual menu and select Delete. Thus all of the elements under the root
    customers are removed. Then you can reconstruct the XML
    tree view to have the best structure used to group the output data of
    interest.

    Use_Case_tXMLMapGroup2.png
  2. Again in the XML tree view of the output side, right-click the root node
    customers to open the contextual menu and select
    Create Sub-Element. Then a dialog box pops
    up.

    Use_Case_tXMLMapGroup3.png
  3. Type in the name of the new sub-element. In this scenario, it is
    Customer.

  4. Repeat the previous operations to create two more sub-elements under this
    Customer node. They are:
    LabelState and Name.

  5. Do these operations again to create two more sub-elements under this newly
    created Name node. They are: id and
    CustomerName.

  6. Right-click the Name node to open the contextual menu and
    select As loop element to set this element as
    loop.

  7. Right-click the Customer node to open its contextual menu
    and select As group element. This means that
    the output data is grouped according to the LabelState
    element.

  8. From the lookup data flow on the input side, click and drop the
    LabelState row to the row of the
    LabelState node in the Expression column on the output side. Thus the corresponding
    data is mapped.

  9. Do the same to map the id element and the
    CustomerName element between both sides. Then this
    modification is done.

    Use_Case_tXMLMapGroup4.png
  10. If required to generate single XML flow, click the wrench icon on top of the
    output side to open the setting panel and set the All in
    one
    feature as true. In this
    example, this option is set as true. For
    further information about the All in one
    feature, see Talend Studio User
    Guide
    .

  11. Click OK to validate this modification and
    close this 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 loop element.

  12. Press F6 to run this Job.

    The execution result reads as follows in the Run view.

    Use_Case_tXMLMapGroup5.png

    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.

    Note

    tXMLMap provides group element and aggregate
    element
    to classify data in the XML tree structure. When
    handling one row of data ( one complete XML flow), the behavioral difference
    between them is:

    • The group element processes
      the data always within one single flow.

    • The aggregate element splits
      this flow into separate and complete XML flows.

Scenario 6: Classing the output data with aggregate element

Based on the Job used in Scenario 5: Mapping data using a group element, this scenario presents how to set
up an element as aggregate element in the Map editor of tXMLMap in
order to class the output data into separate XML flows.

Use_Case_tXMLMap1.png

On the Design workspace, double-click the tXMLMap
component to open its Map editor. There the output side
reads as follows:

Use_Case_tXMLMapGroup4.png

The objective of this scenario is to class the customer information using aggregate
element in accordance with the States they come from and then to send these classes
separately in different XML flows to the component that follows.

Note

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 you need to use as
the aggregating condition. The figure below presents part of the sorted source data
used in this scenario. The customers possessing the same State id is already put
together.

use_case-txmlmap-sorted_source.png

To do this, adjust the output XML tree as follows:

  1. Right-click the Customer element to open its
    contextual menu and from this menu, select Remove group
    element
    .

  2. Click the wrench icon on top of the output side to open the setting panel and
    set the All in one feature as false.

  3. Right-click the LabelState element to open
    its context menu and from this menu, select As aggregate
    element
    . This element tags the State information of each customer
    and the customer information will be classed under the State information.

    Note

    To make the aggregate element available, ensure that the All in one feature is set as false. For further information about the
    All in one feature, see Talend Studio User Guide.

  4. Click OK to validate these changes and close
    the Map editor.

  5. Press F6 to run this Job.

    Once done, the Run view is opened
    automatically, where you can check the execution result.

    use_case-txmlmap_aggregate.png

tXMLMap outputs four separate XML flows, each of
which carries the information of one State and the customers from that State.

Note

tXMLMap provides group
element
and aggregate element to
classify data in the XML tree structure. When handling one row of data ( one
complete XML flow), the behavioral difference between them is:

  • The group element processes the data
    always within one single flow.

  • The aggregate element splits this
    flow into separate and complete XML flows.

Scenario 7: Restructuring products data using multiple loop elements

This scenario uses a four-component Job to restructure the products data given by a
document flow using multiple loop elements.

txmlmap-multiloop3.png

The components used are:

  • tFileInputXML: it reads the source product
    data and pass them to the tXMLMap
    component.

  • tXMLMap: it transforms the input flows with
    the expected structure streamlined.

  • tLogRow: it presents the execution result in
    the console.

  • tFileOutputXML: it generates the output flow
    into an XML file.

The input flow reads as follows:

The objective of this restructuring is to streamline the presentation of the products
information to serve the manufacturing operations.

The output flow is expected to read as follows:

In the output flow, the root element is changed to manufactures, the sales information is selected and consolidated into
the sale element and the manufacture element is reduced to one single level.

To replicate this scenario, proceed as follows:

Dropping and linking the components

To do this, perform the following operations:

  1. On the workspace, drop tFileInputXML, tXMLMap,
    tLogRow and tFileOutputXML from the Palette.

  2. Right-click tFileInputXML to open its
    contextual menu and select the Row >
    Main link from this menu to connect
    this component to the tXMLMap
    component.

  3. Repeat this operation to connect tXMLMap
    to tLogRow using Row > *New Output*
    (Main)
    link. A dialog box pops up to prompt you to name this
    output link. In this scenario, name it as
    outDoc.

  4. Do the same to connect tLogRow to
    tFileOutputXML using the Row > Main
    link.

Configuring the input flow

To do this, do the following:

  1. Double-click tFileInputXML to open its
    Basic settings view.

    use_case-txmlmap_multiloop4.png
  2. Click the […] button next to Edit schema to open the schema editor.

    use_case-txmlmap_multiloop5.png
  3. Click the [+] button to add one row to
    the editor and rename it as doc.

  4. In the Type column, select Document from the drop-down list as the type of
    the input flow.

  5. In the File name/Stream field, browse to
    or type in the path to the XML source that provides the customer
    data.

  6. In the Loop XPath query field, type in
    "/" to replace the default one. This means the source data
    is queried from the root.

  7. In the XPath query column of the
    Mapping table, type in the XPath. In
    this scenario, type in ".", meaning that all of the data from
    source are queried.

  8. In the Get Nodes column of the Mapping table, select the check box.

Configuring tXMLMap with multiple loops

To do this, proceed as follows:

  1. Double-click the tXMLMap component to
    open the Map Editor.

    Note that the input area is already filled with the default basic XML
    structure and that the top table is the main input table.

  2. In the left table, right-click doc to
    open the contextual menu.

    use_case-txmlmap_multiloop6.png
  3. From this contextual menu, select Import From
    File
    and in the pop-up dialog box, browse to the
    corresponding source file in order to import therefrom the XML structure
    used by the data to be received by tXMLMap.
    In this scenario, the source file is input.xml, which
    provides the data read and loaded by tFileInputXML.

  4. In the imported XML tree, right-click the manufacture node and 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 element, respectively.

    use_case-txmlmap_multiloop1.png
  5. On the lower part of this map editor, click the Schema editor tab to display the corresponding view.

  6. On the right side of this view, click the [+] button to add one row to the outDoc table and rename this row as outDoc.

    use_case-txmlmap_multiloop7.png
  7. In the Type column of this
    outDoc row, select Document as the data type. The corresponding XML root is
    added automatically to the top table on the right side which represents the
    output flow.

    use_case-txmlmap_multiloop8.png
  8. On the right side in the top table labelled outDoc, import the XML data structure that you need to use
    from the corresponding XML source file. In this scenario, it is ref.xml. This file provides the expected XML
    structure mentioned earlier.

    use_case-txmlmap_multiloop9.png
  9. Right-click the manufacture node and
    select As loop element from the contextual
    menu. Then do the same to set the types
    node and the sale node as loop element,
    respectively.

    Then you can begin to map the input flow to the output flow.

  10. In the top table on the input side (left) of the map editor, click
    the @category node and drop it to the
    Expression column in the row
    corresponding to the output row you need to map. In this scenario, it is the
    @category node.

    use_case-txmlmap_multiloop10.png
  11. Do the same to map:

    • @name to @name

    • @unit under the summary node to @unit

    • @id to @id and to manufacture id, respectively

    • @date to @date

    • name to @name

    • type to type

    • @type to @sales_type

    • income to sale (loop)

  12. If required to generate single XML flow, click the wrench icon on top of
    the output side to open the setting panel and set the All in one feature as true.
    In this example, this option is set as true. For further information about the All in one feature, see Talend Studio
    User Guide
    .

  13. Click the […] button next to the
    manufacture loop element to open the
    [Configure source loops] dialog box,
    and then click the [+] button to add one
    source loop manufacture. Do the same to
    sale loop element and add one source
    loop sale.

    use_case-txmlmap_multiloop13.png
  14. Click the […] button next to the
    types loop element to open the
    [Configure source loops] dialog box.
    Then click the [+] button to add two source loops types and manufacture,
    and make sure the sequence number of types source loop is 0.
    This way, the relative part of the output flow will be sorted with regards
    to the values of the type element.

    use_case-txmlmap_multiloop11.png

    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, in this scenario the types loop element of the output flow is mapped with
    @id which belongs to the
    manufacture loop element and
    type which belongs to the
    types loop element. The output
    flow will be sorted according to the primary types loop.

  15. Click OK to validate the mappings 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 loop
    element.

Configuring the output flow

To do this, proceed as follows:

  1. Double-click tLogRow to open its
    Component view.

  2. If this component does not have the same schema of the preceding
    component, a warning icon appears. In this case, click the Sync columns button to retrieve the schema from
    the preceding one and once done, the warning icon disappears.

  3. Click OK to validate these changes and
    accept the propagation prompted by the pop-up dialog box.

  4. Double-click tFileOutputXML to open its
    Component view.

    use_case-txmlmap_multiloop2.png
  5. In the File Name field, browse to or
    enter the path to the file you need to generate the output flow in.

  6. Select the Incoming record is a document
    check box.

Executing the Job

To execute this Job, press F6.

Once done, the Run view is opened automatically,
where you can check the execution result.

use_case-txmlmap_multiloop12.png

Open the file generated, and you will see the expected products data restructured
for manufacturing.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x