XQuery

Overview

XQuery was devised primarily as a query language for data stored in XML form. Its main role is to get information out of XML databases. XQuery support is supplied by the camel-saxon module.

Adding the Saxon module

To use XQuery in your routes you need to add a dependency on camel-saxon to your project as shown in Example 22, “Adding the camel-script dependency”.

Example 22. Adding the camel-script dependency

<!-- Maven POM File -->
...
<dependencies>
  ...
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-saxon</artifactId>
    <version>${camel-version}</version>
  </dependency>
  ...
</dependencies>

Variables

Table 15, “XQuery variables” lists the variables that are accessible when using XQuery.

Table 15. XQuery variables

VariableTypeDescription
exchangeExchangeThe current Exchange
in.bodyObjectThe body of the IN message
out.bodyObjectThe body of the OUT message
in.headers.keyObjectThe IN message header whose key is key
out.headers.keyObjectThe OUT message header whose key is key
keyObjectThe Exchange property whose key is key

Example

Example 23, “Route using XQuery” shows a route that uses XQuery.

Example 23. Route using XQuery

<camelContext>
  <route>
    <from uri="activemq:MyQueue"/>
    <filter>
      <language langauge="xquery">/foo:person[@name='James']</language>
      <to uri="mqseries:SomeOtherQueue"/>
    </filter>
  </route>
</camelContext>