• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xpath does not match when namespace prefix changes

 
Arjun Karthick
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Arjun

PS: This is a duplicate post. I have created the same post in the XML certification topic. Kindly delete the other post.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic