You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Deepthi <de...@gmail.com> on 2012/08/07 21:58:22 UTC
Node count in camel
Hi,
Is there a way to find number of nodes in a given xml in camel using spring.
For Eg: We have the following xml:
<order>
<item>1</item>
<item>2</item>
<item>3</item>
</order>
I want to know the number of item tags in order tag and store it in header
name say itemCount.
I am using camel 2.8.0
Is this possible?
Thanks,
Deepthi
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Node count in camel
Posted by dalewking <da...@gmail.com>.
Michal Warecki wrote
> <setHeader headerName="itemCount">
>
> <xpath resultType="java.lang.String">
> count(/order/item)
> </xpath>
> </setHeader>
Apparently the secret part of that is the resultType="java.lang.String".
With it, it works. Without it you get the very misleading:
org.apache.camel.builder.xml.InvalidXPathExpression - Invalid xpath:
count(/order/item)
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946p5737422.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Node count in camel
Posted by Deepthi <de...@gmail.com>.
Thanks Michal.
This works.
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946p5716999.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Node count in camel
Posted by "michal.warecki" <mi...@gmail.com>.
If you want to store count result in header, why you use filtering?
This should work:
<setHeader headerName="itemCount">
<xpath resultType="java.lang.String">count(/order/item)</xpath>
</setHeader>
<log message="${header.itemCount}"></log>
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946p5716966.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Node count in camel
Posted by Deepthi <de...@gmail.com>.
Hi Michal,
I am trying to give in the following manner:
<filter>
<xpath>count(/order/item)</xpath>
</filter>
It is not working. Where am i going wrong?
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946p5716958.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Node count in camel
Posted by "michal.warecki" <mi...@gmail.com>.
There is "count" function in XPath. As I know Saxon can handle this function.
--
View this message in context: http://camel.465427.n5.nabble.com/Node-count-in-camel-tp5716946p5716948.html
Sent from the Camel - Users mailing list archive at Nabble.com.