Hi,
The error message indictes that you haven't passed a definition of the loc 
namespace prefix to the XPath.
Aside from that your code is rather inefficient. You are first mashalling your 
parsed XML document into a String, then instantiate a DOM parser to parse it as 
a DOM and finally apply an XPath expression on it.

You can avoid the former by doing a 
Document document = exchange.getIn().getBody(Document.class); instead of the 
first five lines of your code.

In your place I would do the XPath evaluation also as part of the Camel 
pipeline (e.g. store these values in some camel headers. See
http://camel.apache.org/xpath.html for details).

Best regards
Stephan

-----Original Message-----
From: siddhesh [mailto:[email protected]] 
Sent: Montag, 22. Juni 2015 09:30
To: [email protected]
Subject: RE: Difficulty in extracting data from CxfPayload

Hi Siano, Thanks 

I tried this code 

String bodyStr = exchange.getIn().getBody(String.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new
StringReader(bodyStr)));
XPath xPath = XPathFactory.newInstance().newXPath(); 

String address1 = xPath.evaluate("//loc:address/text()", document);
String address2 = xPath.evaluate("/loc:getLocation/loc:address", document);

but i get error when i try to access address in both ways using xpath
net.sf.saxon.trans.XPathException: Prefix loc has not been declared

Anything I am missing ? 



--
View this message in context: 
http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422p5768458.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to