camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: @XPath evaluation
Date Tue, 28 Aug 2012 02:56:02 GMT
setHeader() should be able to take the XPath expression.
I just add unit test in the camel trunk to show it.

 setHeader("foo").xpath("/personFile/text()").  

--  
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: willemjiang





On Monday, August 27, 2012 at 6:53 PM, Joe San wrote:

> I managed to get that working.
>  
> I have another question on the route configuration:
>  
> Assuming the following xml snippet:
>  
> <pss:info>
> <personFile>098765432.txt</personFile>
> <address>
> <street>xyz</street>
> <city>Frankfurt</city>
> </address>
> <persons>
> <person>
> <name>joe</name>
> <age>32</age>
> <country>Germany</country>
> </person>
>  
> <person>
> <name>sam</name>
> <age>32</age>
> <country>Germany</country>
> </person>
> </persons>
> </pss:info>
>  
> The task was to get the List of Person which I managed to extract using
> xpath. I would also want to get the fileName value and set that as a header
> in my Exchange. My route definition is as below:
>  
> from("file://C:/folders/inbox?noop=true")
>  
> .setFileNameHeader(ns.xpath("/SOAP:Envelope/SOAP:Body/pss:info/personFile/text()"))
> .split(ns.xpath("//SOAP:Envelope/SOAP:Body/pss:info/persons"))
> .bean(new PersonProcessor())
> .to("file://C:/folders/inbox");
>  
> But I get the following error message shown:
>  
> The method setFileNameHeader(XPathExpression) is undefined for the type
> RouteDefinition
>  
> The setHeader also seems to be wrong.
>  
> Regards,
> Jothi
>  
> On Fri, Aug 24, 2012 at 9:35 PM, Christian Müller <
> christian.mueller@gmail.com (mailto:christian.mueller@gmail.com)> wrote:
>  
> > Yes, should be possible.
> >  
> > Sent from a mobile device
> > Am 24.08.2012 13:56 schrieb "Joe San" <codeintheopen@gmail.com (mailto:codeintheopen@gmail.com)>:
> >  
> > > The most common language to use is XPath, which allows you to evaluate
> > > XPath
> > > expressions on the message body. For example, suppose the message
> >  
> >  
> > contains
> > > the following
> > > XML document:
> > >  
> > > <order customerId="123">
> > > <status>in progress</status>
> > > </order>
> > >  
> > > By using XPath expressions, you can extract parts of the document and
> > bind
> > > them to
> > > parameters, like this:
> > >  
> > > public void updateStatus(@XPath("/order/@customerId") Integer customerId,
> > > @XPath("/order/status/text()") String status) {
> > > ....
> > > ....
> > > }
> > >  
> > > The above snippet is from the Camel in Action book. Can I use the @XPath
> > to
> > > evaluate to a List < Person >?
> > >  
> > > My xml would look like this:
> > >  
> > > <info>
> > > <address>
> > > <street>xyz</street>
> > > <city>Frankfurt</city>
> > > </address>
> > >  
> > > <person>
> > > <name>joe</name>
> > > <age>32</age>
> > > <country>Germany</country>
> > > </person>
> > >  
> > > <person>
> > > <name>sam</name>
> > > <age>32</age>
> > > <country>Germany</country>
> > > </person>
> > >  
> > > </info>
> > >  
> > > The XPath should evaluate the fetch the List of Person objects!
> > >  
> > > Regards,
> > > Jothi
> >  
>  




Mime
View raw message