for the first part of the question, maybe you forgot the set the namespace context (the prefix->nsuri map) in the expression?
setNamespaces(Map<String,String> namespaces) for the second part, you probably need to parse the file that will scan all the namespaces declared and you will see them in the corresponding namespace declaration handler. 2013/10/31 Nurali Techie <nurali.tec...@yahoo.com>: > Hi Friends, > > I want to execute xpath in my code. It means; I have xpath expression, I > have exchange object with In Message. > > Using 'XPathExpression' and 'XPathBuilder' classes; I succeed to do so. > Below is the code snippet. > > XPathExpression xpathExprObj = new > XPathExpression("/userResponse/User/id"); > xpathExprObj.setResultType(String.class); > > Object result = xpathExprObj.evaluate(exchange, Object.class); > > But, if I have xpath with namespace (i.e xpath = /ns0:userResponse/User/id).. > above code throwing exception .. saying - Prefix must resolve to a namespace: > ns0 > > Part of Exception: > > org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: > /ns0:userResponse/User/id. Reason: javax.xml.xpath.XPathExpressionException > at > org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:767) > ~[bundlefile:2.11.2-sap-02] > at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:748) > ~[bundlefile:2.11.2-sap-02] > at org.apache.camel.builder.xml.XPathBuilder.evaluate(XPathBuilder.java:168) > ~[bundlefile:2.11.2-sap-02] > at *** My project code calling from here .. > .......... > ------- > Caused by: > com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix > must resolve to a namespace: ns0 > at > com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:653) > ~[na:1.6.0_33] > at > com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:638) > ~[na:1.6.0_33] > at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:265) > ~[na:1.6.0_33] > at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:96) > ~[na:1.6.0_33] > at > com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:110) > ~[na:1.6.0_33] > at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:176) > ~[na:1.6.0_33] > at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:264) > ~[na:1.6.0_33] > at > com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:385) > ~[na:1.6.0_33] > > Upon digging; I found that .. I need to set namespaces to XPathExpression > object .. So, I need list of all namespace. > I am using blueprint beans.xml .. so I need list of all namespaces defined > with blueprint tag in beans.xml. > > I have camel exchange and camel endpoint object with me. > I want programmatic solution. > > Thanks, > Nurali