insert text sibling processor

Insert Text as Sibling processor

Version: 17.07

Supported Since: 17.07

What is an Insert Text as Sibling processor?

An Insert Text Element as Sibling processor is a processing element which accepts a message with an XML payload, selects one or more elements from that by evaluating a provided XPath expression, and then adds a text element with the given name and value as a sibling of that element (i.e as a child of the selected element’s parent). It can be configured whether to add this new element before or after the selected element.

In order to use this processing element, you must first select the Regular XML Processors dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Regular XML Processors dependency.

insert text outports

Out Ports

Next

The message will be sent to this outport if the element addition is executed successfully

On Exception

The message will be sent to this outport if the processing element failed to add the element due to some reason

Parameters

XPath *

Basic

The XPath expression to select the element/s to add the new text element as a sibling

Add before *

Basic

If true the new element will be inserted before the selected element or after otherwise. The default value is true.

Qualified name *

Basic

The qualified name for the new element. A custom prefix can be specified as myns:myelement.

Namespace URI

Basic

If it is required to add a custom namespace URI to the new element, it can be specified as the value of this parameter

Content *

Basic

The text to be set as the content of the new element

Namespaces

Basic

If any custom namespaces are being used inside XPath expression, those should be defined as a map with those namespaces as keys and the corresponding namespace URIs as values.

Sample Use Case

In the following use case, a food item distributor receives item order requests from the retailers through an SFTP server as XML files. The distributor’s system should fetch these orders and uploads them to another SFTP server used by the manufacturer of these items.

This manufacturer has multiple distributors and each one has given a unique identifier. The manufacturer’s system expects this ID as a text element with name <distID> which is the first child of the top level element of each order (i.e. <order> element) to identify which distributor has placed a particular order.

Therefore the requirement is to get the order requests from the source SFTP server, add the distributor’s ID as the first child element of the <order> element with the name distID and then uploads this request to the destination SFTP server.

Prerequisites

In order to implement following use case following dependencies should be selected when an empty Ultra project is being created.

  • SFTP Connector

  • XML Processors

If the project is already created, above dependencies can be added via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies.

insert text flow

In this flow, an SFTP ingress connector is used to retrieve the order requests from the source SFTP server and its "Processor" outport is connected to the inport of the Insert Text Element as Sibling processor so that the XML message received by the connector is handed over to the processor next.

The XPath property of the processor is configured as /order/item[1] to select first <item> element which is currently the first child of the top level <order>. The Add before property is set as true so that the new element will be added before the first <item> element. Then the Qualified name property is configured as distID and Content property is configured as 5467, so that a new text element with the name <distID> will be having the value 5467 which is the ID given for this distributor.

If any custom namespaces are being used inside XPath expression, those should be defined as a map in the Namespaces property, with those namespaces as keys and the corresponding namespace URIs as values.

Similarly a namespace URI can be added to the new element by configuring the Namespace URI property of the processing element.

Finally the "Next" outport of the Add Text as Child processor is connected to an SFTP egress connector so that the resulting message will be uploaded to the destination SFTP server.

Example

For example, assume that the original order request contains the following XML payload.

<?xml version="1.0" encoding="UTF-8"?>
<order>
    <item>
        <id>7685</id>
        <amount>400</amount>
    </item>
    <item>
        <id>2345</id>
        <amount>100</amount>
    </item>
</order>

A text element will be added with name <distID> and value 5467 as the first child of the <order> element (i.e. before the first <item> element) as follows.

<?xml version="1.0" encoding="UTF-8"?>
    <distId>5467</distId>
    <item>
        <id>7685</id>
        <amount>400</amount>
    </item>
    <item>
        <id>2345</id>
        <amount>100</amount>
    </item>
</order>
In this topic
In this topic
Contact Us