Help trying to convert old Apache XPath methods to J2SE5 XPath

Previously using Apache XPath before it was part of J2SE I loaded the xml file into a DOM Document, and then had a method that could lookup by xpath

DocumentBuildFactory dbf = DocumentBuilderFactory.newInstance();

dbf.setValidating(false);

DocumentBuilder db = dbf.newDocumentBuilder();

Document d = db.parse(new File("testfile.xml");

......

node = XPathAPI.selectSingleNode(d.getDocumentElement(),xpath);

return node;

but in the J2SE, XPath only seems to work with (SAX) Input Source, I don't see why It can't be run against a DOM Document.

XPathFactory xpf = XPathFactory.newInstance();

XPath path = xpf.newXPath();

....

XPathExpression xPathExpression = path.compile(xpath);

return xPathExpression.evaluate(is);

Could anybody clarify this for me, thanks Paul

[1015 byte] By [paultaylora] at [2007-11-26 16:06:51]
# 1
Just looking at the API documentation, there's an "evaluate(Object)" method that might be your answer. It describes the single parameter as "The starting context (node or node list, for example)". I haven't used this myself, just guessing based on docs-reading.
DrClapa at 2007-7-8 22:29:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks, think I was a bit dense here although I think the API documentation is pretty poor in this area.
paultaylora at 2007-7-8 22:29:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I don't think it's really the documentation's fault, I think it's a lazy design.

It looks to me like you can pass a Node or a NodeList to that Object parameter, but not much else. Then why not two overloaded methods, one with a Node parameter and the other with a NodeList parameter, and both with decent documentation?

DrClapa at 2007-7-8 22:29:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...