Skip to content

Knowledge Base

White Paper Libary

How to process XML with attributes

Introduction

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 nodes or elements with attributes and the structure will resemble something similar to figure 1:

AttributesFigure1

Figure 1.

Given the XML structure shown in figure 1 above, the task browser window should display a recordset containing six items, three items relating to the three different elements and the data they contain and a further three items relating to the attributes within each element.

However, we can see in figure 2 that the XML Attributes do not register in the Task Browser Window only the data elements are exposed when we view the resultant record set fields.

In order to overcome this we use the DTC within the Web Service Connector tool (WSCT). Instructions follow.

AttributesFigure2

Figure 2.

Solution Description

Step 1

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 ProcessAttributes.
AttributesFigure3

Figure 3.

Step 2

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 ‘ExtractAttributes’. See figure 4.
AttributesFigure4

Figure 4.

Step 3

Double click on the Input section to begin configuring an Input Data Structure. Here we will create a very similar data structure to the source data but with additional Elements. These additional elements will be used to hold the data contained within the source XML’s attributes. Once you have created the data structure, export it and save it somewhere accessible before clicking OK. We can reuse this structure for the output XML.

The screenshot figure 5 shows the schema structure used to define both the input and output schema for this operation.

AttributesFigure5

Figure 5.

Step 4

Now double click on the Output section to begin configuring the Output data structure. Once the screen has opened, click on the import button and select the file we created in the previous step. Once imported, move over to the mappings tab and begin mapping the Input data to the Output data.

The following screenshot figure 6 demonstrates what the mapping tab should look like:

AttributesFigure6

Figure 6.

Step 5

We now return to the Task created earlier and insert a new Web Service Connector Step, selecting the new Web Service Configuration and new MMO.The step should be configured so that it uses the Document Source from the XML Import Tool. Figure 7 refers.
AttributesFigure7

Figure 7.

Step 6

The mapping screen will now show the XML from the source document on the left hand side and the input data structure we created on the right hand side. Notice how the XML on the left hand side contains both elements and attributes now (represented by the ‘@’) sign:

AttributesFigure8

Figure 8.

Mapping the elements and the attributes into our input structure effectively extracts the attribute data successfully and presents it in a format our XML to Recordset tool can understand.

Remember to add a simple loop to iterate through the structure if applicable.

See our e-learning material if you need help in setting up loops in the DTC: Transform Functions – Simple Looping

Step 8

Now change the Convert XML to Recordset tool’s document source to consume the Web Service Connector tool’s Output XML and then open the task browser. Navigate to the Convert XML to Recordset tool’s Recordset and notice how we now see the Output XML Structure we created in the MMO. The Web Service Connector tool step has now extracted the data from the attributes and placed it into the new elements we created.