Java 中的 XPath 节点集
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3350417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XPath NodeSet in Java
提问by denniss
I have this code in eclipse
我在 eclipse 中有这个代码
NodeSet nodes = (NodeSet) xPath.evaluate(expression,inputSource, XPathConstants.NODESET);
and its giving me compile time error on NodeSet.
并且它给了我 NodeSet 上的编译时错误。
These are the stuff that I have imported. Can you tell me why it's doing this?
这些是我进口的东西。你能告诉我为什么这样做吗?
import javax.xml.xpath.*;
import org.xml.sax.InputSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;
回答by Garett
As indicated NodeSet is not part of the standard libraries. However, from the documentation, NodeSet maps to a NodeList, so you could just use that instead. So it would become:
如上所述,NodeSet 不是标准库的一部分。但是,从文档中,NodeSet 映射到一个 NodeList,因此您可以改为使用它。所以它会变成:
NodeList nodes = (NodeList) xPath.evaluate(expression,inputSource, XPathConstants.NODESET);
You would have to import org.w3c.dom.NodeList.
您将不得不导入org.w3c.dom.NodeList.

