Versions Compared

Key

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

...

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

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

Code Block

from("queue:foo").filter().
  xpath("//foo")).
  to("queue:bar")

In earlier versions of Camel you had to use the XPathBuilder To add an XPath expression to your routing rules its usually easiest to import the XPathBuilder classes methods then you can use the xpath() function inside your rules.

Code Block
import static org.apache.camel.builder.xpath.XPathBuilder.*;

...


from("queue:foo").filter(xpath("//foo")).to("queue:bar")

Namespaces

In 1.3 onwards you can easily use namespaces with XPath expressions using the Namespaces helper class.

Code Block

Namespaces ns = new Namespaces("c", "http://acme.com/cheese");

from("direct:start").filter().
    xpath("/c:person[@name='James']", ns).
    to("mock:result");

Examples

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

...