Introduction

This article describes how to process XML attributes in a source document so that they can be processed by other BPA Platform tools.

Why Is This Needed?

Tools that can consume and process XML are able to recognise XML attributes. However, where the data is required by a recordset-only consuming BPA Platform tool, a conversion must take place first. Available conversion tools do not recognise XML attributes so such XML structures must be flattened first.

Example XML Structure

Let's take the following XML:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
	<company id="1">
		<name>Corkery, Graham and Kessler</name>
		<contact>Joshuah Gregorin</contact>
		<address>7 American Ash Court</address>
	</company>
	<company id="2">
		<name>Parisian LLC</name>
		<contact>Natka Mochar</contact>
		<address>98298 Kim Place</address>
	</company>
	<company id="3">
		<name>Spinka, Moen and Jakubowski</name>
		<contact>

and so on.

When you import this file into your task, the structure is recognised correctly — Import XML DocumentClosed The Import XML Document tool imports an XML document to be used and processed by other task steps. To validate the XML documents at runtime, you can either import an XML schema file (XSD), infer from an existing XML document, or manually construct the XSD. tool > Main tab > OutputXML tab. However, when you use the Convert XML to RecordsetClosed The Convert XML to Recordset tool is used to convert XML data into a flat-format BPA Platform recordset, allowing the data to be used by recordset-only consuming tools. This could then be used to power alerts via fax, email, or SMS, create reports, power a workflow, perform FTP transfer, and so on. tool, the created recordset looks like:

BPA Platform - Recordset Output XML Document with Attributes

The attributes are completely ignored for the output.

Adding Attributes to the XML Output

Using the XML example above, we use the Transform DataClosed Transform Data is a Format tool that enables a new structure to be created from an existing XML or recordset data source. The output generated by this tool is ready for use in a destination system which consumes or requires XML. tool to create a flat XML structure where the attribute is converted to an additional XML element. This can then be converted to a recordset structure later, if required, by the Convert XML to Recordset tool.

Do the following:

  1. Import the XML file to the task using the Import XML Document tool.
  2. Add a Transform Data step to the task and consume the output from the previous Import XML Document step.
  1. Go to the Main tab.
  2. Click Add Node and change the Name to the top-level element — in this example, we are using company.
  3. Use Add Element to add the other XML elements.
  4. Add another new element for the attribute — in this example, we have id.
  5. Use the up and down arrows to move the new attribute / element to the required location in the output XML structure.

    Transform Data - Main Tab - Attributes to Elements

  6. Go to the Mapping tab and map the original elements to new (click and drag one element to the other):

    Transform Data - Mapping Tab - Attributes to Elements

    You'll notice in the example above that the parent element company is also mapped. This forces the Transform Data tool to "step through" the input XML document to ensure that for every company record found, a mapped record is created in the output XML. Without this, only the first record encountered is outputted. When creating the mapping, a Simple function is automatically created — no further configuration is required for this.

  7. Click OK to save the step.
  8. You can now add a Convert XML to Recordset step to create the correct recordset then continue with the task.

The recordset should now look like:

BPA Platform - Recordset Output from with XML Attributes

The recordset can now be successfully consumed and processed by other BPA Platform tools. Note how the column names are also prefixed with the parent XML node name too.

Article originally published 03 December 2015 — Article updated 02 March 2020