Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Explicit type conversion when using functions in query

...

In earlier versions of Camel you had to use theXQueryBuilder methods then you can use the xquery() function method inside your rules.

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

You can also use functions inside your query, in which case you need an explicit type conversion (or you will get a org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR) by passing the Class as a second argument to the xquery() method.

Code Block

from("direct:start").
  recipientList().xquery("concat('mock:foo.', /person/@city)", String.class);

Using XML configuration

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

...

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

When you use functions in your XQuery expression you need an explicit type conversion which is done in the xml configuration via the @type attribute:

Code Block
langxml

    <xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery>

Using XQuery as an endpoint

...