XPath NodeSet in Java

和自甴很熟 提交于 2019-12-23 07:57:23

问题


I have this code in eclipse

NodeSet nodes = (NodeSet) xPath.evaluate(expression,inputSource, XPathConstants.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.*;

回答1:


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);

You would have to import org.w3c.dom.NodeList.



来源:https://stackoverflow.com/questions/3350417/xpath-nodeset-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!