• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

xpath does not match when namespace prefix changes

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic