You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by paramjyotsingh <pa...@gmail.com> on 2012/06/12 00:17:50 UTC

XPath Filter not working

Hi,

I am trying to use XPath, but somehow it is not responding the way it is
supposed to.

Example i have a xml input of type:-

<Products>
   <Product type="BOX">
   ..
   </Product>
</Products>

and I am trying spring dsl filter:-

<route>
  <from uri="file:///test/folder" />
  <filter>
     <xpath>/Products/Product[@type='BOX']</xpath>
     <to uri="file://test/matchedFile" />
  </filter>
</route>

with XML input i provided the filter should match Xpath predicate and should
move file to /test/mactchedFile folder. But this is not happening

Please help me to resolve this issue.

Regards,
Paramjyot

--
View this message in context: http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XPath Filter not working

Posted by Bob Jolliffe <bo...@gmail.com>.
On 27 June 2012 10:46, Christian Müller <ch...@gmail.com> wrote:
> Shouldn't your use:
>
> <split>
>  <xpath>/Feeds/Feed</xpath>
>  <to uri="file:///out/"/>
> </split>

A bit verbose, but if you cannot easily work around the namespace
mapping you can also try
<xpath>/*[local-name()='Feeds']/*[local-name()='Feed']</xpath>

Or in the likely case that 'Feed' is the only child of 'Feeds'
<xpath>/*[local-name()='Feeds']/*</xpath>

>
> if your input is:
>
> <Feeds xmlns="urn:myXML">
>  <Feed>Test1</Feed>
>  <Feed>Test2</Feed>
> </Feeds>
>
> as you explained?
>
> And as documented in [1], xpath will load the entire document into memory:
> -> not suitable for verry big payloads
> -> streaming="true" doesn't work
>
> And what Claus blogged in his blog (using tokenizeXML) is not possible in
> Camel 2.8.x. You have to use Camel 2.9.x for that, as documented in [1]...
>
> [1] http://camel.apache.org/splitter.html
>
> Best,
> Christian
>
> On Tue, Jun 26, 2012 at 10:46 PM, paramjyotsingh
> <pa...@gmail.com>wrote:
>
>> Hi Claus,
>>
>> I read this article from you,
>> http://www.davsclaus.com/2011/11/splitting-big-xml-files-with-apache.html
>> about splitting big XML into small pieces.
>>
>> I am trying to do same thing in camel 2.8.1 but <tokenize> does not work
>> the
>> same way it works in 2.9.2
>>
>> In 2.8.1 i am using following mechanism to split:-
>>
>> <split streaming="true">
>>   <xpath>/Records/Record</xpath>
>>   <to uri="file:///out/"/>
>> </split>
>>
>> My Target i want to achieve:-
>> Input XML
>>
>> <Feeds xmlns="urn:myXML">
>>   <Feed>Test1</Feed>
>>   <Feed>Test2</Feed>
>> </Feeds>
>>
>> XML after split should be:-
>>
>> <Feed xmlns="urn:myXML">Test1</Feed>
>> and
>> <Feed xmlns="urn:myXML">Test2</Feed>
>>
>> Please let me know how to achieve this in camel 2.8.x.
>>
>> Thanks and Regards,
>> Paramjyot Singh
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5715131.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>

Re: XPath Filter not working

Posted by Christian Müller <ch...@gmail.com>.
Shouldn't your use:

<split>
  <xpath>/Feeds/Feed</xpath>
  <to uri="file:///out/"/>
</split>

if your input is:

<Feeds xmlns="urn:myXML">
  <Feed>Test1</Feed>
  <Feed>Test2</Feed>
</Feeds>

as you explained?

And as documented in [1], xpath will load the entire document into memory:
-> not suitable for verry big payloads
-> streaming="true" doesn't work

And what Claus blogged in his blog (using tokenizeXML) is not possible in
Camel 2.8.x. You have to use Camel 2.9.x for that, as documented in [1]...

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

Best,
Christian

On Tue, Jun 26, 2012 at 10:46 PM, paramjyotsingh
<pa...@gmail.com>wrote:

> Hi Claus,
>
> I read this article from you,
> http://www.davsclaus.com/2011/11/splitting-big-xml-files-with-apache.html
> about splitting big XML into small pieces.
>
> I am trying to do same thing in camel 2.8.1 but <tokenize> does not work
> the
> same way it works in 2.9.2
>
> In 2.8.1 i am using following mechanism to split:-
>
> <split streaming="true">
>   <xpath>/Records/Record</xpath>
>   <to uri="file:///out/"/>
> </split>
>
> My Target i want to achieve:-
> Input XML
>
> <Feeds xmlns="urn:myXML">
>   <Feed>Test1</Feed>
>   <Feed>Test2</Feed>
> </Feeds>
>
> XML after split should be:-
>
> <Feed xmlns="urn:myXML">Test1</Feed>
> and
> <Feed xmlns="urn:myXML">Test2</Feed>
>
> Please let me know how to achieve this in camel 2.8.x.
>
> Thanks and Regards,
> Paramjyot Singh
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5715131.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: XPath Filter not working

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

If you use xpath as the expression for splitting XML. Then spent time
to google and learn a bit more how to do that.

The biggest problem is often that with xpath you must make sure the
namespace mapping is correct.
And yes it can be a bit of problem to get it working. I suggest if
there is some tool / plugin in your IDE etc.
to do live xpath expressions and see until it works.




On Tue, Jun 26, 2012 at 10:46 PM, paramjyotsingh
<pa...@gmail.com> wrote:
> Hi Claus,
>
> I read this article from you,
> http://www.davsclaus.com/2011/11/splitting-big-xml-files-with-apache.html
> about splitting big XML into small pieces.
>
> I am trying to do same thing in camel 2.8.1 but <tokenize> does not work the
> same way it works in 2.9.2
>
> In 2.8.1 i am using following mechanism to split:-
>
> <split streaming="true">
>   <xpath>/Records/Record</xpath>
>   <to uri="file:///out/"/>
> </split>
>
> My Target i want to achieve:-
> Input XML
>
> <Feeds xmlns="urn:myXML">
>   <Feed>Test1</Feed>
>   <Feed>Test2</Feed>
> </Feeds>
>
> XML after split should be:-
>
> <Feed xmlns="urn:myXML">Test1</Feed>
> and
> <Feed xmlns="urn:myXML">Test2</Feed>
>
> Please let me know how to achieve this in camel 2.8.x.
>
> Thanks and Regards,
> Paramjyot Singh
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5715131.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.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: XPath Filter not working

Posted by paramjyotsingh <pa...@gmail.com>.
Hi Claus,

I read this article from you,
http://www.davsclaus.com/2011/11/splitting-big-xml-files-with-apache.html
about splitting big XML into small pieces.

I am trying to do same thing in camel 2.8.1 but <tokenize> does not work the
same way it works in 2.9.2

In 2.8.1 i am using following mechanism to split:-

<split streaming="true">
   <xpath>/Records/Record</xpath>
   <to uri="file:///out/"/>
</split>

My Target i want to achieve:-
Input XML

<Feeds xmlns="urn:myXML">
   <Feed>Test1</Feed>
   <Feed>Test2</Feed>
</Feeds>

XML after split should be:-

<Feed xmlns="urn:myXML">Test1</Feed>
and
<Feed xmlns="urn:myXML">Test2</Feed>

Please let me know how to achieve this in camel 2.8.x.

Thanks and Regards,
Paramjyot Singh

--
View this message in context: http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5715131.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XPath Filter not working

Posted by paramjyotsingh <pa...@gmail.com>.
I am getting this email from external source, Is there any other way to
resolve this issue. Other wise i have to make some code tweaks/ or have to
come up with some logic in bean it self.

--
View this message in context: http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5714448.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XPath Filter not working

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jun 12, 2012 at 9:02 PM, paramjyotsingh <pa...@gmail.com>wrote:

> I tried following configurations:-
>  -- <convertBodyTo type="java.lang.String" />
>  -- <convertBodyTo type="String" />
>
> I have only default namespace xmlns="urn:feed"
>
>
Then you use a namespace, and you must map that to your xpath expression.



> Even with above configurations no luck.
>
>
Yeah getting xpath working can be a challenge.


> Camel version i am using is 2.9.2
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5714379.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.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: XPath Filter not working

Posted by paramjyotsingh <pa...@gmail.com>.
I tried following configurations:-
 -- <convertBodyTo type="java.lang.String" />
 -- <convertBodyTo type="String" />

I have only default namespace xmlns="urn:feed"

Even with above configurations no luck. 

Camel version i am using is 2.9.2


--
View this message in context: http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310p5714379.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XPath Filter not working

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jun 12, 2012 at 12:17 AM, paramjyotsingh
<pa...@gmail.com>wrote:

> Hi,
>
> I am trying to use XPath, but somehow it is not responding the way it is
> supposed to.
>
> Example i have a xml input of type:-
>
> <Products>
>   <Product type="BOX">
>   ..
>   </Product>
> </Products>
>
> and I am trying spring dsl filter:-
>
> <route>
>  <from uri="file:///test/folder" />
>  <filter>
>     <xpath>/Products/Product[@type='BOX']</xpath>
>     <to uri="file://test/matchedFile" />
>  </filter>
> </route>
>
> with XML input i provided the filter should match Xpath predicate and
> should
> move file to /test/mactchedFile folder. But this is not happening
>
> Please help me to resolve this issue.
>
>
What version of Camel are you using?

And are you using any namespaces in your XML? If so the xpath expression
must have namespace mapping as well.

Also you can try to force loading the file content into memory before the
xpath filter, using convert body to:
 <from uri="file:///test/folder" />
 <convertBodyTo type="String"/>
 <filter>



Regards,
> Paramjyot
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/XPath-Filter-not-working-tp5714310.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.com
Author of Camel in Action: http://www.manning.com/ibsen