File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XPathAPI and namespaces 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 "XPathAPI and namespaces" Watch "XPathAPI and namespaces" New topic
Author

XPathAPI and namespaces

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
I'm having a problem with XPATH and namespaces.
Could anyone please help ?

I'm using apache XPathAPI, with java 1.4.
It works fine as long as there are no namespaces.
Unfortunately, when adding namespaces to the xml, XPathAPI fails to find the desired element (returning null).



What am i doing wrong ? Do you know of a better way to do it ?
Thanks.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
Originally posted by Sol Mam-Orn:


Thanks.


If you do like this, does it work?

Node subNode = XPathAPI.selectSingleNode(root, "tempuri:body/tempuri:status", nsResolverNode);
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311

Originally posted by Jesus Angeles:
If you do like this, does it work?

Node subNode = XPathAPI.selectSingleNode(root, "tempuri:body/tempuri:status", nsResolverNode);


Thanks for replying... unfortunately this suggestion doesn't work
(it gives a runtime error message, which actually makes sense here: "prefix must resolve to a namespace: tempuri" ).
 
 
subject: XPathAPI and namespaces
 
Similar Threads
xpath does not match when namespace prefix changes
document root attributes?
DOM String output is not the same as original XML
How to perform an XPath Query with namespaces.
Facing problem with JAXB1.0