Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath NodeSet in Java

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.*;
like image 759
denniss Avatar asked Jul 28 '10 06:07

denniss


People also ask

What is XPath evaluate?

XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expressions. context. If a request is made to evaluate the expression in the absence of a context item, an empty document node will be used for the context.


1 Answers

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.

like image 117
Garett Avatar answered Oct 24 '22 19:10

Garett