jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes XPATH and namespaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPATH and namespaces" Watch "XPATH and namespaces" New topic

XPATH and namespaces

JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Given the following XML doc
then xpath.selectSingleNode(theNode,"/AAA/BBB") returns the node BBB.

If the doc uses a default namespace, then I have to prefix the node name with an empty Namespace
e.g : xpath.selectSingleNode(theNode,"/:AAA/:BBB")

And in a namescape with a prefix like :


my XPATH now needs to be like :

Is there a way to define the namespace xpath will use to resolve outside of the XPATH string.
I would like to be able to use :
xpath.selectSingleNode(theNode,"/AAA/BBB") no matter the prefix used in my XML doc.
I've tried to figure out how the PrefixResolver works..... but I failed :-(

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
I agree. Here's the link: http://aspose.com/file-tools
subject: XPATH and namespaces
It's not a secret anymore!