|
XQuery has been edited by Claus Ibsen (Sep 25, 2008). Content:XQueryCamel supports XQuery from("queue:foo").filter(). xquery("//foo")). to("queue:bar")
Using XML configurationIf you prefer to configure your routes in your Spring XML file then you can use XPath expressions as follows <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:[EMAIL PROTECTED]'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! 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: <xquery type="java.lang.String">concat('mock:foo.', /person/@city)</xquery> Using XQuery as an endpointSometimes an XQuery _expression_ can be quite large; it can essentally be used for Templating. So you may want to use an XQuery Endpoint so you can route using XQuery templates. The following example shows how to take a message of an ActiveMQ queue (MyQueue) and transform it using XQuery and send it to MQSeries. <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:MyQueue"/> <to uri="xquery:com/acme/someTransform.xquery"/> <to uri="mqseries:SomeOtherQueue"/> </route> </camelContext> ExamplesHere is a simple example from("direct:start").filter().xquery("/[EMAIL PROTECTED]'James']").to("mock:result"); This example Namespaces ns = new Namespaces("c", "http://acme.com/cheese"); from("direct:start"). filter().xquery("/c:[EMAIL PROTECTED]'James']", ns). to("mock:result"); Learning XQueryXQuery is a very powerful language for querying, searching, sorting and returning XML. For help learning XQuery try these tutorials
You might also find the XQuery function reference DependenciesTo use XQuery in your camel routes you need to add the a dependency on camel-saxon which implements the XQuery language. If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions). <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> <version>1.4.0</version> </dependency> |
Unsubscribe or edit your notifications preferences
