本文介绍了Java 中的 XPath 节点集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在eclipse中有这个代码
I have this code in eclipse
NodeSet nodes = (NodeSet) xPath.evaluate(expression,inputSource, XPathConstants.NODESET);
并且它在 NodeSet 上给了我编译时错误.
and its giving me compile time error on 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.*;
推荐答案
如上所述,NodeSet 不是标准库的一部分.但是,从 文档, NodeSet 映射到一个 NodeList,所以你可以直接使用它.所以它会变成:
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:
NodeList nodes = (NodeList) xPath.evaluate(expression,inputSource, XPathConstants.NODESET);
您必须导入 org.w3c.dom.NodeList
.
这篇关于Java 中的 XPath 节点集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!