XPath overview

The XML Path Language (XPath) is used to uniquely identify or address parts of an XML document. An XPath expression can be used to search through an XML document, and extract information from any part of the document, such as an element or attribute (referred to as a node in XML) in it. XPath can be used alone or in conjunction with XSLT.

Some of the built-in nodes provided in the IBM® Integration Toolkit can use XPath expressions to specify the part of a message that is processed by the node. For example, you can use an XPath expression to identify fields in a message and determine if they match a specified value, or to set the field value by updating it with the results of a database query.

You can use XPath 1.0 path expressions in your flow to access specific parts of an incoming message, create or locate parts of an outgoing message, and perform complex message processing that might involve values present in message trees accessible by a node so that you can transform, filter, or retrieve values from a message.

For example, the Route node applies XPath 1.0 general expressions to the content of message trees associated with the incoming message assembly for this node. Following evaluation of an expression the result is cast as a Boolean (true or false) result, and this in turn is used to determine if a copy of the incoming message is routed down an output terminal associated with the processed expression.

If you have XML schema or DFDL message definition files (.xsd), or Message Sets (.mxsd) present in your workspace, any elements, attributes or data types defined in such definitions can be loaded into the Data types viewer and selected to automatically generate a path expressions mapping to the definition concerned.

Equally, depending on the XPath expressions supported by the property concerned, you can select XPath functions and operators to include in an expression, or you can build your own expressions manually.

The Data types viewer contains a list of variables relating to trees that can be accessed by expressions for the node property concerned.

For example, $InputRoot gives access to the incoming message tree. The fixed format of standard folders you can expect to exist under this tree, for example, Properties and MQMD are described without the need to import an .mxsd definition for them. These structures can be navigated in the viewer and, on selection of an element within them, a path expression that maps to the element in question is built automatically through the XPath 1.0 language.

For further information on XPath 1.0 see W3C XPath 1.0 Specification.

You can use the XPath Expression Builder to visually build XPath expressions to set the relevant properties in your nodes. You launch the XPath Expression Builder from buttons located along side property fields present in the Properties viewer, for those nodes that support the use of XPath expressions as property values.

The XPath files in IBM Integration Bus are supplied in three property editors; see XPath property editors for more details.

The XPath editor supports both content-assist directly on the text field and also an Edit… button that launches the XPath builder dialog. The dialog gives you a larger area in which to build your XPath expressions.

The content assist based control contains two different proposal lists in the following order:
  1. Nodes and Variables
  2. Functions and Operators

The node and variable proposals are displayed the first time that you use the XPath editor. In this view, the status bar reads Press Ctrl+Space to show Function and Operation Proposals.

Pressing Ctrl+Space when you are in the function and operator level proposals selects the Node and Variable proposals.

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.