[jdom-interest] problem with xpath

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Aug 19 01:04:16 PDT 2003

prashant sharma wrote:
> I want to get the element ns1:asonReplyMessage0000_MSG. I was using 
> xpath explorer to find out the xpath expression of the elements and 
> xpath explorer gives the xpath expression as 
> /Workspace/GetLocationInfo/Reply/ns1:asonReplyMessage0000_MSG. When I 
> use this xpath expression in my code, it doesn't returns any element 
> from the document. What am I doing wrong. Maybe I am not specifying the 
> xpath expression correctly. Can someone help me.

You need to declare the namespace prefix ns1 to the XPath engine, using the 
addNamespace() method:
    xpath.addNamespace("ns1", "http://www.omg.org/IDL-MAPPED");

Note that XPath does not care about the prefix used in the document or whether 
a prefix is being used.
Thus, the namespace prefix you declare in the XPath expression doesn't have to 
be "ns1".


More information about the jdom-interest mailing list