camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nurali Techie <>
Subject Re: Namespace list - blueprint - xpath
Date Fri, 01 Nov 2013 22:31:29 GMT
Hi All,

I have got the solution .. :)

I have used xpath expression to get all namespace.  Here is the part of code:

        String searchAllNamespacesXpathExpr = "//namespace::*";    // xpath expr to
search all namespace
        XPathExpression nsXpath = new XPathExpression(searchAllNamespacesXpathExpr);
        NodeList nsNodeList = (NodeList) nsXpath.evaluate(exchange, Object.class);  //
this NodeList contains all namespaces

From NodeList object, I prepare namespace Map which I set to XpathExpression object.

        XPathExpression xpathExprObj = new XPathExpression("/ns0:userResponse/User/id)");
        xpathExprObj.setNamespaces(namespaceMap);     // set namespace Map which was
prepared from NodeList
        Object result = xpathExprObj.evaluate(exchange, Object.class);

Now, xpath with namespace (i.e /ns0:userResponse/User/id) will be evaluated correctly.

Thanks Aki and All for you help.

Let me know; in case you see any flaw in above way.


On Friday, November 1, 2013 2:50 PM, Nurali Techie <> wrote:
Thanks Aki for your thoughts ..

Yes, I should call setNamespaces() .. but I need namespace Map which I can pass to ..
So, my question remain same .. is there any API or service .. which I can use to get Namespace
Map ..
And I hv Camel Exchange and Camel Endpoint object with me ..

Parsing blueprint beans.xml and to extract Namespace from <blueprint> tag; looks hack
and dirty way ..
Also, I don't know how can I get beans.xml InputStream to parse for .. 

I also debugged and found that .. for standard <xpath> tag having namespace xpath in
beans.xml .. the blueprint container do magic to pass all namespace while creating xpath expression
object.  It means; namespace list is with blueprint container .. but I don't know how I can
reached to there when I only have Camel Exchange and Endpoint object with me.


On Thursday, October 31, 2013 9:24 PM, Aki Yoshida <> wrote:

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 <>:
> 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( ~[bundlefile:2.11.2-sap-02]
> at org.apache.camel.builder.xml.XPathBuilder.evaluate( ~[bundlefile:2.11.2-sap-02]
> at org.apache.camel.builder.xml.XPathBuilder.evaluate( ~[bundlefile:2.11.2-sap-02]
> at *** My project code calling from here ..
> ..........
> -------
> Caused by: Prefix
must resolve to a namespace: ns0
> at
> at ~[na:1.6.0_33]
> at ~[na:1.6.0_33]
> at ~[na:1.6.0_33]
> at
> at<init>( ~[na:1.6.0_33]
> at<init>( ~[na:1.6.0_33]
> at ~[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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message