- Solution Description
How to process XML with Elements with the Same Name #
This article assumes you are conversant with using the TaskCentre DTC (Data Transformation Component) to transform the structure and content of XML data used within TaskCentre. If you are viewing this knowledge base article then you wish to process XML that contains multiple nodes or elements all with the same name and the structure will resemble something similar to figure 1:
Figure 1. XML data
In the Task Browser screen, shown in figure 2, we can see that the Tool has only presented one ‘SampleNodeName’ element as a recordset where in fact we should see three versions of the same node as each Row of ‘SampleXML’ contains three child elements with the same node name.
Figure 2. Task Browser
Solution Description #
Step 1 – Create a New Web Service Configuration #
Create a New Web Service Configuration in the Global Configuration of the Web Service Connector Tool, selecting the last radio button as shown in figure 3 below. We have called this ‘ProcessElements’.
Figure 3. New Configuration
Step 2 – Create a new Multi Message Operation (MMO) #
Create a new Multi Message Operation (MMO), we will not need any Single Message Operations as we are only going to be using the Data Transformation Component (DTC) to transform the data and not communicating with any Web Service. In this example we have called the new operation ‘ExtractDataFromDuplicateNames’. See figure 4.
Figure 4. HTTP Web Service Cinfiguration
Step 3 – Configuring the Input Data Structure #
Double click on the Input section to begin configuring an Input Data Structure. We’re going to create a flattened structure in order to make the XML as easily accesible as possible. Create an input schema that resembles figure 5:
Figure 5. Multiple Message Input Data
Step 4 – Configuring the Output Data Structure #
Now double click on the Output section to begin configuring the Output data structure. Here we will create an Output data structure which resembles the Input data structure except for the addition of another node. See figure 6:
Figure 6. Multiple Message Output Data
Step 5 – Input and Output schema #
Now that we have an Input and Output schema we will begin to create the loops in the mapping tab. The output schema contains an extra node which in this example is called ‘ElementNode’. Our mapping will ask the tool to create a new element node everytime the tool encounters a new iteration of the element with the same name (in this example the element ‘SameNodeName’).
First drag the ‘ParentNode’ node from the left hand side onto the ‘ParentNode’ node on the right hand side; this will ask the tool to loop through every ‘ParentNode’ supplied. Next, to create the loop on the element you will need to drag and drop a new ‘Simple Loop’ from the functions panel into the DTC. Now click on the ‘Element’ Element on the left hand side and drag it onto the ‘SimpleLoop’ we have just created.
Repeat this process dragging the ‘ElementNode’ node from the right hand side onto the new ‘SimpleLoop’. The tool will now produce a new ‘ElementNode’ everytime it encounters a new ‘Element’. Finally, map the ‘Element’ Element on the left hand side to the ‘Element’ Element on the right hand side to move the data across. The mapping screen should now resemble figure 7.
Figure 7. Multiple Message Mapping
Step 6 – Web Service Connector Step #
We now return to the Task design and insert a new Web Service Connector Step, selecting the new MMO we have created and using the same Document Source from the Import XML Document tool.
Step 7 – Configure the Mapping #
We will now need to configure the mappings for the task step. Notice on the left hand side we can see the input data structure with only a single ‘SameNodeName’ element visible, this is what we’d expect to see.
We now need to configure the mapping screen to loop on the ‘SampleXML’ node and a further loop on the ‘SameNodeName’ element. Simply click on the ‘SampleXML’ node and drag it across to the ‘SameElementName’ node on the right hand side.
Next, to create the loop on the element you will need to drag and drop a new ‘Simple Loop’ from the functions panel into the DTC. Once completed, click on the ‘SameNodeName’ element on the left hand side and drag it onto the new ‘Simple Loop’ you have just created. You will see a black mapping line appear from the element and connect to the ‘Simple Loop’.
Now click on the ‘ParentNode’ node on the right hand side and drag it onto the new ‘Simple Loop’ to finish creating the loop. Finally, map the ‘SameNodeName’ on the left hand side to the ‘Element’ element on the right hand side to move the data across. Figure 8 below demonstrates how the Tool’s mapping screen should look:
Figure 8. Configured Mapping
This will generate an XML Document with one ‘ParentNode’ per row and one ‘ElementNode’ per duplicated element, so taking the input XML as an example we will generate six iterations of ‘ElementNode’ containing the six different pieces of data, these six iterations will be divided between the two ‘ParentNode’ rows mimicking the input data structure.