मैं निम्नलिखित कोड है:सैक्सन XPath एपीआई org.w3c.dom.Node
// 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);
और यह परिणाम है ...
class net.sf.saxon.tinytree.TinyElementImpl class java.util.ArrayList false false
बस स्पष्ट करने के लिए , अगर मैं ऐसा करते हैं:
org.w3c.dom.Node node = (org.w3c.dom.Node)evaluate;
या
org.w3c.dom.NodeList node = (org.w3c.dom.NodeList)evaluate2;
मैं एक ClassCastException
कैसे है कि हो सकता है मिल सकता है? संस जावा 1.5 API नोड अनुसार और nodeset org.w3c.dom.Node
और org.w3c.dom.NodeList
करने के लिए नक्शे चाहिए क्रमशः
बस clarify2 को हाँ मैं जानता हूँ कि नोड एक iterface है, कि getClass() एक ठोस वर्ग देता है।
समझ में आता है .... यदि आप डब्ल्यू 3 सी डोम डालते हैं, तो आपको डब्ल्यू 3 सी डोम मिल जाता है। अन्यथा, आप मालिकाना डोम बाहर मिलता है। – skaffman
जावा एक्सएमएल में आपका स्वागत है। – Esko