Creating XPath expressions

Many message flow nodes provide properties that can be specified using an XPath 1.0 expression, for example properties to set data locations for Monitoring or Security where this language is used to form a path expression to locate incoming message body elements. The Mapping node supports XPath 2.0 functions and expressions.

About this task

Other less common node property fields support the entry of general XPath 1.0 expressions that support a wider range of the language to perform more complex evaluations in the integration node's XPath 1.0 runtime engine.

Note: In the Graphical Data Mapping editor, you can use XPath 2.0 functions and expressions. You can use XPath functions to define graphical transformations in your message. You can use XPath expressions to define conditions for your transformations.

The XPath Expression builder provides a tree view of a message, and supports the automatic generation of an XPath 1.0 path expression, through the selection of an element within the tree.

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

Procedure

  1. Add the relevant node to your message flow
  2. In the Properties viewer, enter the correlation name, or press Ctrl + Space to use content assist, or press Edit to use the Expression editor.
    Content assist is also invoked by simply typing $ in cell-based property fields. See Correlation names for further information on correlation names.
  3. Expand the tree, navigate to the field for which you want to build an expression, and click to select it.
    A field is either an element, or an attribute.
    Double-click the field to add it to the XPath expression. You can also drag fields, functions, and operators to the desired location in the XPath expression when using the XPath Expression builder.
  4. To set conditions, enter them as you would a normal XPath Expression.

Results

The complete XPath expression is shown either:
  • In the XPath Expression pane if you are using the XPath Expression builder.

    The Expression builder dialog is an optional aid for generating expressions that, when complete, form the value in a node's property field.

    If you do not use the Expression builder dialog, the expressions entered manually are validated using the property editor.

  • In the Property field if it is in the node itself.
Messages are displayed at the top of the XPath Editor window to alert you to the fact that a path or expression you have entered is not valid.
Note: The editor does not prevent you from entering, and saving, an expression that is not valid.

Example

Here is the XPath expression built in the XPath Expression Builder to filter the Employee business objects for all employees who are managers: $Root/XMLNSC/getEmployeeInfo/Emp[isManager=true()].
  • $Root/XMLNSC/: The body section of the message; that is, the last child of root. This example assumes that the XMLNSC domain is being used.
  • /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.
In this case the same expression works for both request and response flows, because the input and output messages for the operation are identical.

For more information on XPath 1.0, see W3C XPath 1.0 Specification.