Defining XPath
XML Messages going through a route can also be selected based on XPath. To define the XPath, select the route and click Edit button in the Message Body XPath section in Selectors property tab.
Figure 1: Opening Message Body XPath editor
This will launch an editor showing a list of namespaces and their prefixes. You can add/edit namespace prefixes from the table here.
Figure 2: Dialog showing namespace prefixes and the XPath launcher
Clicking the small button under XPath section launches an XPath editor. It displays the message body structure on the left and a canvas to build XPath on the right (Figure 2); details are explained in the section below.
XPath Editor
XPath Editor can be used for specifying path expressions to identify nodes in an XML document and for specifying conditions. The list of elements from schema provided are shown in the left panel of the editor. An element can be selected by dragging it to the right panel.
Figure 3: Xpath Editor with a sample schema
An XPath expression may consist of different constant values, functions or/and operators. These can be added easily by right clicking on the right panel and selecting the option based on the requirement.
Figure 4: Adding a constant in XPath Editor
Adding a Function
A function can be added by any of the following ways:
- Right-click in the right side panel and selecting Add Function option.
- Select from the list available in the Palette tab present at the bottom of the left panel.
Figure 5: Palette containing different XPath functions on the left and a sample XPath expression on the right
As per the connections made in the above figure, a string function 'matches' takes two arguments and returns a boolean value.
Adding a Constant value
Supported types of constants are String, Boolean, Numeric, Date-Time, and Duration.
To add a boolean value, perform the following actions:
- Right-click in the right panel, go to Add Constant and select Boolean Value.
- Select the desired boolean value (true/false) from the drop-down as shown in the figure below.
Figure 6: Adding a boolean constant
Adding a Operator
To add an operator, perform the following actions:
- Right-click in the right panel and select Add Operator.
- Select the desired operator from the drop-down as shown in the figure below.
Figure 7: Adding an operator
Sample XPath using Add Operator
If you add an Add (+) operator and then two numeric constant values to feed values (to pass arguments) to the operator, the Xpath expression looks as in the figure below.
Figure 8: Sample Xpath expression
Message Body XPath Selector
After adding the constant values, functions or/and operators etc as per requirement, when you click OK in the XPath editor, a new selector will be added to the route. Below is the result of the XPath expression as shown in Figure 5.
Figure 9: Message Body XPath Selector as seen in the Properties panel for the route (result of XPath expression in Figure 5)