Quantcast

Node count in camel

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Node count in camel

Deepthi
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Node count in camel

Michal Warecki
There is "count" function in XPath. As I know Saxon can handle this function.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Node count in camel

Deepthi
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?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Node count in camel

Michal Warecki
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>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Node count in camel

Deepthi
Thanks Michal.
This works.
Loading...