You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by MichaelAtSAG <me...@gmail.com> on 2011/12/07 21:45:09 UTC

How do I use xpath functions in Camel?

I receive errors when trying to use xpath functions. My example below is
simplified, but I want to use an xpath expression to set a header property
in the Camel Spring XML context, like this:

Camel context:
-----
<camelContext xmlns="http://camel.apache.org/schema/spring">
	<route id="Test">
		<setHeader headerName="Test">
			<xpath>string(315)</xpath>
		</setHeader>
	</route>
</camelContext>


Error:
-----
org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
string(315). Reason: javax.xml.xpath.XPathExpressionException

How do I write this xpath expression in Camel?

Any help is greatly appreciated.

Thanks!

--
View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5056913.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I use xpath functions in Camel?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I think saxon supports xpath functions and some of the 2.0 functions
as well. We have a little example here
http://camel.apache.org/xpath.html


On Wed, Dec 7, 2011 at 11:14 PM, MichaelAtSAG <me...@gmail.com> wrote:
> Hi Raul,
>
> I am away for computer, but I am running the latest version of Camel at 2.8.3.
>
> Many other context files work, yet this one fails with the error shown initially. It fails when running in Eclipse or from maven.
>
> Does that simple set xpath command work on your system?
>
> Michael
>
> On Dec 7, 2011, at 2:21 PM, "Raul Kripalani [via Camel]" <ml...@n5.nabble.com> wrote:
>
>> Can you test that very particular example on your Camel installation? Make
>> sure you add the resultType attribute on the xpath element, i.e.
>> resultType="java.lang.String". Otherwise it is assumed that the result will
>> be a NodeList which it isn't in this case.
>>
>> It looks like we may have lost the culprit of this error due to
>> oversimplification of the example for posting.
>>
>> On the other hand, if it actually fails on your environment, please post
>> the version of Camel you are running on and more details of the environment
>> ;)
>>
>> On 7 December 2011 20:45, MichaelAtSAG <[hidden email]> wrote:
>>
>> > I receive errors when trying to use xpath functions. My example below is
>> > simplified, but I want to use an xpath expression to set a header property
>> > in the Camel Spring XML context, like this:
>> >
>> > Camel context:
>> > -----
>> > <camelContext xmlns="http://camel.apache.org/schema/spring">
>> >        <route id="Test">
>> >                <setHeader headerName="Test">
>> >                        <xpath>string(315)</xpath>
>> >                </setHeader>
>> >        </route>
>> > </camelContext>
>> >
>> >
>> > Error:
>> > -----
>> > org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
>> > string(315). Reason: javax.xml.xpath.XPathExpressionException
>> >
>> > How do I write this xpath expression in Camel?
>> >
>> > Any help is greatly appreciated.
>> >
>> > Thanks!
>> >
>> > --
>> > View this message in context:
>> > http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5056913.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>> >
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057005.html
>> To unsubscribe from How do I use xpath functions in Camel?, click here.
>> NAML
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057152.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: How do I use xpath functions in Camel?

Posted by Raul Kripalani <ra...@fusesource.com>.
Currently the XPath Spring DSL element doesn't allow specifying Saxon or a
different factory.
The only option now is to use a system property, as per the last section in
[1].

Alternatively, if you only have a few headers to set using XPath 2.0, you
can use the XQuery language in Camel which automatically defaults to Saxon,
making all of XPath 2.0's goodness available to you as a side effect ;)

-- Raúl.

[1] http://camel.apache.org/xpath.html.

On 9 December 2011 11:57, Raul Kripalani <ra...@fusesource.com> wrote:

> Hi,
>
> You need Saxon to run XPath 2.0 functions. The JDK default for JAXP is
> Xalan I believe, which only supports XPath 1.0.
> XPath 1.0 included several functions [1] but nowhere near as powerful and
> useful as XPath 2.0 [2].
>
> The string function exists in XPath 1.0 and it is available to use within
> Camel without Saxon in the classpath - I just tested it with the following
> config:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="
> http://www.springframework.org/schema/util"
>  xsi:schemaLocation="
>            http://www.springframework.org/schema/beans
>            http://www.springframework.org/schema/beans/spring-beans.xsd
>            http://camel.apache.org/schema/spring
>            http://camel.apache.org/schema/spring/camel-spring.xsd
>            http://www.springframework.org/schema/util
>            http://www.springframework.org/schema/util/spring-util.xsd">
>
>    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>  <route id="timer">
>   <from uri="timer:test?fixedRate=true&amp;period=10000" />
>     <setBody><constant><![CDATA[<hello />]]></constant></setBody>
>     <setHeader headerName="test">
>        <xpath resultType="java.lang.String">string('313')</xpath>
>     </setHeader>
> <to uri="log:StartTest?showAll=true" />
>  </route>
>  </camelContext>
>
> </beans>
> Regards,
> Raúl.
>
> [1] http://www.w3.org/TR/xpath/#corelib
> [2] http://www.w3.org/TR/xpath-functions/
>
> On 9 December 2011 11:39, Claus Ibsen <cl...@gmail.com> wrote:
>
>> You may have luck by just included camel-saxon, and thus saxon on the
>> classpath, which may let the JDK use Saxon as its XPath engine.
>>
>>
>> On Thu, Dec 8, 2011 at 5:51 PM, MichaelAtSAG <me...@gmail.com>
>> wrote:
>> > Ok, I am hearing that I need to use Saxon to run xpath functions versus
>> the
>> > default camel-core component. Correct? To do this, I have added this to
>> the
>> > pom.xml:
>> >
>> >        <dependency>
>> >                <groupId>org.apache.camel</groupId>
>> >                <artifactId>camel-saxon</artifactId>
>> >        </dependency>
>> >
>> > The examples in the Apache Camel: Xpath page show the use of Java code
>> to
>> > use Saxon. It is possible to use Saxon in Spring XML versus Java
>> methods?
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5059406.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
>

Re: How do I use xpath functions in Camel?

Posted by Raul Kripalani <ra...@fusesource.com>.
Hi,

You need Saxon to run XPath 2.0 functions. The JDK default for JAXP is
Xalan I believe, which only supports XPath 1.0.
XPath 1.0 included several functions [1] but nowhere near as powerful and
useful as XPath 2.0 [2].

The string function exists in XPath 1.0 and it is available to use within
Camel without Saxon in the classpath - I just tested it with the following
config:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="
http://www.springframework.org/schema/util"
 xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://camel.apache.org/schema/spring
           http://camel.apache.org/schema/spring/camel-spring.xsd
           http://www.springframework.org/schema/util
           http://www.springframework.org/schema/util/spring-util.xsd">

   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
 <route id="timer">
  <from uri="timer:test?fixedRate=true&amp;period=10000" />
    <setBody><constant><![CDATA[<hello />]]></constant></setBody>
    <setHeader headerName="test">
       <xpath resultType="java.lang.String">string('313')</xpath>
    </setHeader>
<to uri="log:StartTest?showAll=true" />
 </route>
 </camelContext>

</beans>
Regards,
Raúl.

[1] http://www.w3.org/TR/xpath/#corelib
[2] http://www.w3.org/TR/xpath-functions/

On 9 December 2011 11:39, Claus Ibsen <cl...@gmail.com> wrote:

> You may have luck by just included camel-saxon, and thus saxon on the
> classpath, which may let the JDK use Saxon as its XPath engine.
>
>
> On Thu, Dec 8, 2011 at 5:51 PM, MichaelAtSAG <me...@gmail.com>
> wrote:
> > Ok, I am hearing that I need to use Saxon to run xpath functions versus
> the
> > default camel-core component. Correct? To do this, I have added this to
> the
> > pom.xml:
> >
> >        <dependency>
> >                <groupId>org.apache.camel</groupId>
> >                <artifactId>camel-saxon</artifactId>
> >        </dependency>
> >
> > The examples in the Apache Camel: Xpath page show the use of Java code to
> > use Saxon. It is possible to use Saxon in Spring XML versus Java methods?
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5059406.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Re: How do I use xpath functions in Camel?

Posted by Claus Ibsen <cl...@gmail.com>.
You may have luck by just included camel-saxon, and thus saxon on the
classpath, which may let the JDK use Saxon as its XPath engine.


On Thu, Dec 8, 2011 at 5:51 PM, MichaelAtSAG <me...@gmail.com> wrote:
> Ok, I am hearing that I need to use Saxon to run xpath functions versus the
> default camel-core component. Correct? To do this, I have added this to the
> pom.xml:
>
>        <dependency>
>                <groupId>org.apache.camel</groupId>
>                <artifactId>camel-saxon</artifactId>
>        </dependency>
>
> The examples in the Apache Camel: Xpath page show the use of Java code to
> use Saxon. It is possible to use Saxon in Spring XML versus Java methods?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5059406.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: How do I use xpath functions in Camel?

Posted by MichaelAtSAG <me...@gmail.com>.
Ok, I am hearing that I need to use Saxon to run xpath functions versus the
default camel-core component. Correct? To do this, I have added this to the
pom.xml:

	<dependency>
		<groupId>org.apache.camel</groupId>
		<artifactId>camel-saxon</artifactId>
	</dependency>

The examples in the Apache Camel: Xpath page show the use of Java code to
use Saxon. It is possible to use Saxon in Spring XML versus Java methods?

--
View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5059406.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I use xpath functions in Camel?

Posted by Raul Kripalani <ra...@fusesource.com>.
Yes, it does.

On 7 Dec 2011, at 22:15, MichaelAtSAG <me...@gmail.com> wrote:

> Hi Raul,
>
> I am away for computer, but I am running the latest version of Camel at 2.8.3.
>
> Many other context files work, yet this one fails with the error shown initially. It fails when running in Eclipse or from maven.
>
> Does that simple set xpath command work on your system?
>
> Michael
>
> On Dec 7, 2011, at 2:21 PM, "Raul Kripalani [via Camel]" <ml...@n5.nabble.com> wrote:
>
>> Can you test that very particular example on your Camel installation? Make
>> sure you add the resultType attribute on the xpath element, i.e.
>> resultType="java.lang.String". Otherwise it is assumed that the result will
>> be a NodeList which it isn't in this case.
>>
>> It looks like we may have lost the culprit of this error due to
>> oversimplification of the example for posting.
>>
>> On the other hand, if it actually fails on your environment, please post
>> the version of Camel you are running on and more details of the environment
>> ;)
>>
>> On 7 December 2011 20:45, MichaelAtSAG <[hidden email]> wrote:
>>
>>> I receive errors when trying to use xpath functions. My example below is
>>> simplified, but I want to use an xpath expression to set a header property
>>> in the Camel Spring XML context, like this:
>>>
>>> Camel context:
>>> -----
>>> <camelContext xmlns="http://camel.apache.org/schema/spring">
>>>       <route id="Test">
>>>               <setHeader headerName="Test">
>>>                       <xpath>string(315)</xpath>
>>>               </setHeader>
>>>       </route>
>>> </camelContext>
>>>
>>>
>>> Error:
>>> -----
>>> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
>>> string(315). Reason: javax.xml.xpath.XPathExpressionException
>>>
>>> How do I write this xpath expression in Camel?
>>>
>>> Any help is greatly appreciated.
>>>
>>> Thanks!
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5056913.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057005.html
>> To unsubscribe from How do I use xpath functions in Camel?, click here.
>> NAML
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057152.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I use xpath functions in Camel?

Posted by MichaelAtSAG <me...@gmail.com>.
Hi Raul,

I am away for computer, but I am running the latest version of Camel at 2.8.3. 

Many other context files work, yet this one fails with the error shown initially. It fails when running in Eclipse or from maven. 

Does that simple set xpath command work on your system?

Michael

On Dec 7, 2011, at 2:21 PM, "Raul Kripalani [via Camel]" <ml...@n5.nabble.com> wrote:

> Can you test that very particular example on your Camel installation? Make 
> sure you add the resultType attribute on the xpath element, i.e. 
> resultType="java.lang.String". Otherwise it is assumed that the result will 
> be a NodeList which it isn't in this case. 
> 
> It looks like we may have lost the culprit of this error due to 
> oversimplification of the example for posting. 
> 
> On the other hand, if it actually fails on your environment, please post 
> the version of Camel you are running on and more details of the environment 
> ;) 
> 
> On 7 December 2011 20:45, MichaelAtSAG <[hidden email]> wrote: 
> 
> > I receive errors when trying to use xpath functions. My example below is 
> > simplified, but I want to use an xpath expression to set a header property 
> > in the Camel Spring XML context, like this: 
> > 
> > Camel context: 
> > ----- 
> > <camelContext xmlns="http://camel.apache.org/schema/spring"> 
> >        <route id="Test"> 
> >                <setHeader headerName="Test"> 
> >                        <xpath>string(315)</xpath> 
> >                </setHeader> 
> >        </route> 
> > </camelContext> 
> > 
> > 
> > Error: 
> > ----- 
> > org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: 
> > string(315). Reason: javax.xml.xpath.XPathExpressionException 
> > 
> > How do I write this xpath expression in Camel? 
> > 
> > Any help is greatly appreciated. 
> > 
> > Thanks! 
> > 
> > -- 
> > View this message in context: 
> > http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5056913.html
> > Sent from the Camel - Users mailing list archive at Nabble.com. 
> > 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057005.html
> To unsubscribe from How do I use xpath functions in Camel?, click here.
> NAML


--
View this message in context: http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5057152.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I use xpath functions in Camel?

Posted by Raul Kripalani <ra...@fusesource.com>.
Can you test that very particular example on your Camel installation? Make
sure you add the resultType attribute on the xpath element, i.e.
resultType="java.lang.String". Otherwise it is assumed that the result will
be a NodeList which it isn't in this case.

It looks like we may have lost the culprit of this error due to
oversimplification of the example for posting.

On the other hand, if it actually fails on your environment, please post
the version of Camel you are running on and more details of the environment
;)

On 7 December 2011 20:45, MichaelAtSAG <me...@gmail.com> wrote:

> I receive errors when trying to use xpath functions. My example below is
> simplified, but I want to use an xpath expression to set a header property
> in the Camel Spring XML context, like this:
>
> Camel context:
> -----
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>        <route id="Test">
>                <setHeader headerName="Test">
>                        <xpath>string(315)</xpath>
>                </setHeader>
>        </route>
> </camelContext>
>
>
> Error:
> -----
> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
> string(315). Reason: javax.xml.xpath.XPathExpressionException
>
> How do I write this xpath expression in Camel?
>
> Any help is greatly appreciated.
>
> Thanks!
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-do-I-use-xpath-functions-in-Camel-tp5056913p5056913.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>