...
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 XPath expressions directly using smart completion in your IDE as follows:
Code Block |
---|
from("queue:foo"). filter().xpath("//foo")). to("queue:bar") |
Code Block |
---|
from("queue:foo").
choice().xpath("//foo")).to("queue:bar").
otherwise().to("queue:others");
|
Notice: The xpath is outside the filter node; after the ( ) braces.
In earlier versions of Camel you had to use the XPathBuilder methods then you can use the xpath() function inside your rules.
Code Block |
---|
import static org.apache.camel.builder.xml.XPathBuilder.*; ... from("queue:foo").filter(xpath("//foo")).to("queue:bar") |
Code Block |
import static org.apache.camel.builder.xml.XPathBuilder.*; ... from("queue:foo").choice(xpath("//foo")).to("queue:bar"). otherwise().to("queue:others"); |
...
Namespaces
In 1.3 onwards you can easily use namespaces with XPath expressions using the Namespaces helper class.
...