<html>
I've been loading XML documents (with Namespaces defined) and running
XPath queries over them.<br>
I've not been able to make the XPath queries return the correct nodes,
until I've stripped out the namespace references before loading the file
(ie the namespace.prefix and namespace.uri members for the Elements are
""). I then reset them recursively with
Element.setNamespace(Namespace ns);<br><br>
I downloaded the jaxen libs and tried their samples, which use
web.xml as an input file. <br>
The XPath bits worked fine until I added a Namespace to
web.xml.<br><br>
I tried XPath.addNamespace() but without any joy, eg following retuns 0
items in List:<br>
<tt>Namespace
ns=Namespace.getNamespace("<a href="http://www.xxxx.com/envelope" eudora="autourl">http://www.xxxx.com/envelope</a>");<br>
XPath xp = XPath.newInstance("/TopLevElement");<br>
xp.addNamespace(ns);<br>
List xlist = xp.selectNodes(tdoc);<br><br>
</tt>Looking at an Element of this example,
.namespace.prexif="" and
.namespace.uri="<a href="http://www.xxxx.com/envelope" eudora="autourl">http://www.xxxx.com/envelope</a>",
so it looks like there should be a match.<br><br>
Can anyone provide some sample code to do XPath in the presence of
non-empty Namespaces?<br>
thanks<br>
Jon<br><br>
<x-sigsep><p></x-sigsep>
Jon Sharp tel: +44 1273 504004
mobile: +44 7739 430793 <br>
</html>