Here you can find the source of xpathEvalElements(String expr, Object e)
public static List<Element> xpathEvalElements(String expr, Object e)
//package com.java2s; import java.util.ArrayList; import java.util.List; import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { private final static XPath xpath = XPathFactory.newInstance().newXPath(); public static List<Element> xpathEvalElements(String expr, Object e) { NodeList nl = xpathEvalNodes(expr, e); List<Element> res = new ArrayList<Element>(); for (int i = 0; i < nl.getLength(); i++) { res.add((Element) nl.item(i)); }/*from www . j a v a 2 s . c o m*/ return res; } public static NodeList xpathEvalNodes(String expr, Object e) { return (NodeList) xpathEval(expr, e, XPathConstants.NODESET); } public static Object xpathEval(String expr, Object e, QName type) { try { return xpath.evaluate(expr, e, type); } catch (Exception exc) { throw new RuntimeException("Cannot evaluate xpath expression.", exc); } } }