Example XPath expressions for event filtering

Use numeric, string, or Boolean expressions when configuring an event source, to determine whether the event is emitted.

When you configure an event source, using either monitoring properties or a monitoring profile, you use an XPath expression to determine whether the event is emitted.
  • If the event is always required, use true().
  • If the event is required only in certain circumstances, use an expression of the form
    xpath-query relational-operator value

Comparing numeric values

To emit an event only when the value is greater than 10 000, for example, enter an expression such as this:
$Body/StockTrade[1]/Details[1]/Value[1] > 10000
The [1] suffixes in the query specify that the first occurrence of the element within its parent is required. If these suffixes are not specified, the XPath engine searches the message for other occurrences of each element. This search might adversely affect performance.

Comparing string values

To emit an event only when the company is "Stock Co" for example:
$Body/StockTrade[1]/Details[1]/Company[1] = 'Stock Co'

Comparing Boolean values

Consider the example of a shares transfer approval. The approval flag in the message tree is a Boolean value. You cannot simply specify the element name, because this always returns true if the element exists. Instead, you query the value of the element, and compare the value to the string 'true' to yield the actual true or false result. The XPath query is:
$Body/StockTrade[1]/Shares[1]/Transfer[1]/Approved[1] = 'true'

XPath queries that return a nodeset, such as $Body/StockTrade[1]/Details[1], are always evaluated as false, because they cannot be converted to a Boolean value.