The moose likes XML and Related Technologies and the fly likes xpath does not match when namespace prefix changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xpath does not match when namespace prefix changes" Watch "xpath does not match when namespace prefix changes" New topic

xpath does not match when namespace prefix changes

Arjun Karthick
Ranch Hand

Joined: Jan 04, 2007
Posts: 77
Hi all,

The question might seem simple, but I'm not able to figure the solution.

I need to extract the text node of a particular element. This is the sample xml document

I am using the following xpath to extract.

This is not extracting the value as the namespace prefix does not match. Is there a work around. It works if namespace prefix in the xpath is changed.

Thanks and Regards

PS: This is a duplicate post. I have created the same post in the XML certification topic. Kindly delete the other post.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

It doesn't matter whether the prefix is the same or different. What does matter is the namespace URI applied to the prefixes in the two places; that should be the same.

In the XML document I can see the namespace URI which is applied to the "ns" prefix. But I don't see the code where you apply a namespace URI to the "tns" prefix in your XPath expression. Perhaps you didn't apply any? If you are asking about a javax.xml.xpath.XPath object (you didn't mention that) then the setNamespaceContext method is how you do that.
I agree. Here's the link: http://aspose.com/file-tools
subject: xpath does not match when namespace prefix changes
Similar Threads
Axis rejects int parameter
SOAP Fault for SOAP Action property
Could not recognize the SOAP XML Namespace while invoking MessageRouterServlet
XML->Data Interchange????
NullPointerException returned from webservice