XPath NodeSet in Java

I have this code in eclipse

NodeSet nodes = (NodeSet) xPath.evaluate(expression,inputSource, XPathConstants.NODESET); 

and this gives me a compile-time error in NodeSet.

This is the material that I imported. Can you tell me why this is done?

 import javax.xml.xpath.*; import org.xml.sax.InputSource; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.*; 
+7
java xml xpath nodesets
source share
1 answer

As indicated, NodeSet is not part of the standard libraries. However, from the documentation, NodeSet maps to NodeList, so you can simply use this instead. Thus, it will become the following:

 NodeList nodes = (NodeList) xPath.evaluate(expression,inputSource, XPathConstants.NODESET); 

You will need to import org.w3c.dom.NodeList .

+15
source share

All Articles