Hi You can use xpath builder, see http://camel.apache.org/xpath.html
Something like Integer num = XPathBuilder.xpath("/numbers/month/ca/text()").evaluate(original, Integer.class); On Tue, Jul 15, 2014 at 2:46 PM, Licia <alicia.pari...@gmail.com> wrote: > Hi everyone ! > > I'm still new to camel and I'm trying to use the enrich methode and the > aggregation strategy. > What's I'm trying to do is merging 2 xml files that look alike, like *this* > : > > <?xml version="1.0" encoding="UTF-8"?> > <numbers> > <month name ="Janvier"> > <ca>12</ca> > <margin>2</margin> > </month> > </numbers> > > and *that* : > <?xml version="1.0" encoding="UTF-8"?> > <numbers> > <month name ="Janvier"> > <ca>14</ca> > <margin>5</margin> > </month> > </numbers> > > And obtain one merged where the numbers are added. > > I managed to concatenate them, so I think enriching is okay with me, but I > can't seem be able to adapt my aggregationStrategy. > > Here's *my route* : > > public class XmlRoute extends RouteBuilder > { > public void configure() throws Exception > { > AggregationStrategy aggregationStrategy = new > myAggregationStrategy(); > from ("file:src/data/xmlTest") > > .pollEnrich("file:src/data/xmlToAppend?fileName=just.xml", > aggregationStrategy) > .to("file:src/data/xmlResult"); > } > } > > Here's my* aggregation Strategy* : > public class myAggregationStrategy implements AggregationStrategy { > > public Exchange aggregate(Exchange original, Exchange resource) { > int originalBody = > original.getIn().xpath("/numbers/month/ca/text()").getBody(Integer.class); > int resourceResponse = > resource.getIn().xpath("/numbers/month/ca/text()").getBody(Integer.class); > int mergeResult = originalBody + resourceResponse; // combine > original body and resource response > if (original.getPattern().isOutCapable()) { > original.getOut().setBody(mergeResult); > } else { > original.getIn().setBody(mergeResult); > } > return original; > } > > } > > > of course it doesn't work because I tried to put xpath in the middle of > nothing inside the exchange. > > What I would like to know is if I can express my xpath inside my aggregation > strategy ? If not, do I have to do it inside my routes ? > > Thank you for your help. > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Using-xpath-inside-an-exchange-tp5753868.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/