Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Camel supports XQuery to allow an Expression or Predicate to be used in the DSL or Xml Configuration. For example you could use XQuery to create an Predicate in a Message Filter or as an Expression for a Recipient List.

To enable XQuery support you need the camel-saxon library to be on your classpath.

From 1.3 of Camel onwards you can use XQuery expressions directly using smart completion in your IDE as follows

...

Code Block
import static org.apache.camel.builder.saxon.XQueryBuilder.*;
...
from("queue:foo").
  filter(xquery("//foo")).
  to("queue:bar")

Using XML configuration

If you prefer to configure your routes in your Spring XML file then you can use XPath expressions as follows

Code Block
langxml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:foo="http://example.com/person"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="activemq:MyQueue"/>
      <filter>
        <xquery>/foo:person[@name='James']</xquery>
        <to uri="mqseries:SomeOtherQueue"/>
      </filter>
    </route>
  </camelContext>
</beans>

Notice how we can reuse the namespace prefixes, foo in this case, in the XPath expression for easier namespace based XQuery expressions!

Examples

Here is a simple example using an XQuery expression as a predicate in a Message Filter

...