I have the following code:
// xpath evaluates to net.sf.saxon.xpath.XPathEvaluator XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expression = xpath.compile("/foo/bar"); Object evaluate = expression.evaluate(someXML, XPathConstants.NODE); Object evaluate2 = expression.evaluate(someXML, XPathConstants.NODESET); System.out.println(evaluate!=null?evaluate.getClass():"null"); System.out.println(evaluate2!=null?evaluate2.getClass():"null2"); System.out.println(evaluate instanceof Node); System.out.println(evaluate2 instanceof NodeList);
and this is the result ...
class net.sf.saxon.tinytree.TinyElementImpl
class java.util.ArrayList
false
false
To clarify if I do this:
org.w3c.dom.Node node = (org.w3c.dom.Node)evaluate;
or
org.w3c.dom.NodeList node = (org.w3c.dom.NodeList)evaluate2;
I get a ClassCastException
How can it be? according to Suns Java 1.5, the NODE and NODESET APIs must map to org.w3c.dom.Node and org.w3c.dom.NodeList respectively
For clarification only 2 yes. I know that NODE is an iteration that getClass () returns a specific class.
java java-api saxon
Eran medan
source share