Here you can find the source of getXmlElements(Document inXml, String xpath)
public static List<Element> getXmlElements(Document inXml, String xpath)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import java.util.ArrayList; import java.util.List; public class Main { private static XPath xPath; public static List<Element> getXmlElements(Document inXml, String xpath) { try {/*from ww w . ja va 2 s . com*/ NodeList nodeList = (NodeList) xPath.evaluate(xpath, inXml, XPathConstants.NODESET); List<Element> results = new ArrayList<>(); for (int i = 0; i < nodeList.getLength(); i++) { results.add((Element) nodeList.item(i)); } return results; } catch (Exception ex) { throw new RuntimeException("Could not run xpath: " + xpath, ex); } } }