Camel Apache: xpath to extract some value out of received XML -
during camel routes, query server (a http get) , result, receive 200 ok xml body looking similar this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <userprofiles xmlns="http://www.mycompany.com/aecontext/xmldata">   <userprofile name="guest">     <userprofileattributes>       <userprofileattribute name="parameter1" value="data1" namevisibility="all"/>         <userprofileattribute name="parameter2" value="data2" namevisibility="all"/>       <userprofileattribute name="parameter3" value="data3" namevisibility="all"/>     </userprofileattributes>   </userprofile> </userprofiles> any idea how able value of "parameter2" in xml part (in example 'data2') , store value in exchange property ? guess using xpath expression ? or ... help.
an easy way retrieve value use xpath language. allow extract data want , set somewhere (header, body , ...). here how set parameter2 header value:
<setheader headername="parameter2">   <xpath resulttype="java.lang.string">     /userprofiles/userprofile/userprofileattributes/userprofileattribute[2]/@value   </xpath> </setheader> using java dsl
an example using java dsl , setting message body:
final namespaces ns = new namespaces("c", "http://www.mycompany.com/aecontext/xmldata");  // existing code from(...)   .setbody(     ns.xpath(       "/c:userprofiles/userprofile/userprofileattributes/userprofileattribute[2]/@value",          string.class)    )    .to(...); 
Comments
Post a Comment