IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Services and service-related functions > Building mediation flows > Create XPath expressions

XPath Example: Mediation Flow

This topic shows how XPath is used in a Message Filter primitive to route the message to different terminals based on the conditions set.

The Message Filter primitive takes XPath expressions as properties and decides where the input message will be routed based on the expressions entered. If none of the expressions evaluate to true, the message is routed to the default terminal.

This example illustrates a simple order processing scenario. Each order contains a field for the age of the order and one for the priority of the order, along with customer information. In this example, an order will be given high priority if its age is greater than 14 days. The priority can also be changed manually if needed.

The business object used in this example has the structure show below:

The interface used in this example is:

The mediation flow created is:

For more information on how the a Mapping primitive works, see the Message Transformation section of the documentation. For the purposes of this example, we will be looking at the Message Filter primitive and ignoring the rest.

When the Message Filter primitive is dropped on the canvas, it has a default terminal, a match terminal and a fail terminal as outputs. To add another terminal, right click the primitive and select Add Output Terminal. Name the new terminal highPriority. We are now ready to set the primitive's properties.

The Message Filter properties page is a table which holds the XPath expressions in its rows. To add an expression, click Add... In the Add/Edit Properties wizard, click Edit... to start the XPath Expression Builder.

First, we want to test if the age of the order is greater than 14 days. To do this, expand the ServiceMessageObject to the orderAge : int node. The Expression field should read /body/getPO/input/orderAge.

Next, we add the condition. In the Add an optional condition section, click the Operator field, and click the arrow to see the list of available operators. Select the greater than operator ( > ). In the value field, enter 14. Click OK.

In the Add/Edit properties wizard, the Patterns field shows the completed XPath expression /body/getPO/input/orderAge > '14'.

Next, select the terminal from the drop down list. Click the list and select highPriority. This instructs the primitive to route the message to the high priority terminal when the XPath expression in the Pattern field evaluates to True. Click Finish.

Follow the same procedure to add the second condition to the message filter. The XPath Expression you want is /body/getPO/input/highPriority = 'true'.

You can also copy and paste this expression or type it in the pattern field to save time.

At run time, the order will enter the Message Filter primitive where it will be analyzed. If the age of the order is greater than 14 days or if it has been given a high priority, it will be sent to the high priority terminal. Otherwise, it will continue to the default output terminal.

Create XPath expressions