Building XPath expressions

Most mediation primitives have properties that are specified using an XPath 1.0 expression; for example the root property takes an XPath 1.0 expression which specifies the part of the message that is available to the primitive for processing. The XPath Expression Builder provides a tree view of the message, and allows you to visually build an XPath 1.0 expression or to manually specify an XPath 1.0 expression.

You can use XPath 1.0 expressions in your flow to access specific parts of a message. You can then process the message; for example you can transform, filter or retrieve values from a message,

The input message is displayed in the XPath Expression Builder's schema viewer. Wire the primitive's input terminal before you launch the XPath Expression Builder, so that the complete message is available in the schema viewer.

The XPath Expression Builder is typically launched by clicking the Custom XPath button in the details properties view of a node or mediation primitive. For properties that are set in a table, click on the end of an expression to see the button XPath expression builder launch button that launches the XPath Expression Builder.

The Schema Viewer section provides a tree view of the input message. To visually build your XPath expression follow these steps:

  1. Expand the tree, navigate to the field for which you want to build the expression, and click to select it. A field is either an element, or an attribute which is shown with a preceding @ character in its name. Repeating elements are shown with brackets []. To select a repeating element, click on it and enter an index value when prompted. As you click on a field, you will see the XPath Location being updated to show the location path of the selected element
  2. When you have selected an element, optionally set a condition; click Condition to make a selection from a list of available fields. Use these fields if you need to filter or select by specifying a value. Select a condition field, and then click on Value to set the value against which to compare. For attributes or simple elements (no sub-elements), you can also select self::node() which means use the value of the attribute, or the text part of the element between its beginning and ending tags. At runtime, the condition will be used to select the instance data.

The complete XPath expression is shown under the title Full XPath Expression:

You can enter an XPath expression manually by selecting the Override check box and typing your expression. Or, if you want to build complex expressions, you can begin by creating an expression using the expression builder, then select Override to edit it.

Note: The syntax of your XPath 1.0 expression will not be checked.

Example

The following example shows the relationship between a business object in the interface and an XPath condition in the XPath Expression Builder.

An Employee business object is created containing four fields: id, isManager, name, and department.
Picture of Employee business object

The Employee business object is used as the input and output message types for the EmployeeInterface.


Picture of EmployeeInterface
Here is the corresponding XPath expression built in the XPath Expression Builder to filter the Employee business objects for all employees who are managers: /body/getEmployeeInfo/Emp[isManager=true()].
  • /body: The body section of the message
  • /getEmployeeInfo: The name of the operation in the interface.
  • /Emp: The name of the input message type.
  • [isManager=true()]: Checks whether the isManager field is set to true.
Note: In this case the same expression will work for both request and response flows, but only because the input and output messages for the operation are identical.

The following picture shows the example XPath 1.0 expression in the XPath Expression Builder:

Picture of example in the XPath Expression Builder

See http://www.w3.org/TR/xpath for more information on XPath 1.0.

Related tasks
Defining source and target operations
Adding mediation primitives to the flow
Wiring a mediation flow

Related information

Setting properties in mediation flows

Feedback
(C) Copyright IBM Corporation 2005, 2006. All Rights Reserved.