When creating event-driven or API flows in IBM App Connect, you might sometimes need to pass XML content that’s stored in one application into another application as input. App Connect provides a built-in XML parser that you can use to map XML data from an event or action to a subsequent node in a flow. The XML parser transforms a string of XML text in UTF-8 encoding into an XML object representation of the string. The parser supports versions 1.0 and 1.1 of the XML specification.

The XML parser is available from the Toolbox tab in the flow editor.

Defining the data to be parsed and generating valid XML schema

We’ll use an example to describe how the XML parser works. Let’s suppose that you want create a flow that adds new product information from suppliers into your database management system. The product information is in plain-text XML format, and is uploaded as an XML file to your SFTP server for processing.

After setting up your flow to retrieve the contents of an XML file that was uploaded to your SFTP server, you need to insert an XML parser node from the App Connect toolbox. You can use this node to define the data that you want to parse and to generate valid XML schema. To insert and configure the XML parser node, complete the following steps:

  1. Click the (+), go to the Toolbox tab, and then click XML parser.

    Selecting the XML parser from the Toolbox tab

  2. Use the XML Input field to specify which data from the previous action or event should be parsed. You can map to fields that are shown in the list of available inputs (generally accessible by clicking Insert a reference Insert a reference icon). Typically, this would be the contents of an XML file or some other XML content in a body of text. In our example, we are mapping to the contents of a file in the SFTP server.

    XML Input entry showing a mapped field

  3. Expand the Output Schema section and click Generate an XML schema.

    Generate an XML schema link

  4. In the “Generate an XML Schema” panel, use the Sample XML field to specify an XML representation of the content that you want to parse.

    In our example, the sample XML uses the following elements to describe our product data: a <productinfo> root element, a <product> child element with a category attribute, and nested <productid>, <name>, <description>, <price>, and <manufacturer> siblings.

    Sample XML field

    Consideration for completing the Sample XML field:

    • The Sample XML field accepts a maximum of 16,000 characters.
  5. To convert the sample XML into an XML object, click Generate schema. The generated schema is displayed as a tree structure that shows each element with its data type, as well as any attributes.

    Generated XML schema tree in an XML parser node

    Tip: To modify the schema, you can click Regenerate schema to reopen the “Generate an XML Schema” panel and specify a different XML sample.

Ways of processing your parsed data

The output from an XML parser node is an array. So, to use this output in a subsequent node in the flow, you’d typically include a For each node after the XML parser node to iterate through the array, or you could manipulate the array data by using JSONata.

Join The Discussion

Your email address will not be published. Required fields are marked *