Here you can find the source of getNodesByXPath(Element parent, String name)
public static List<Node> getNodesByXPath(Element parent, String name) throws XPathExpressionException
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static List<Node> getNodesByXPath(Element parent, String name) throws XPathExpressionException { List<Node> result = new ArrayList<>(); NodeList nodeList = findNodesByXPath(parent, name); for (int i = 0, l = nodeList.getLength(); i < l; i++) { result.add(nodeList.item(i)); }// w w w .ja v a 2 s . c om return result; } public static NodeList findNodesByXPath(Node contextNode, String expression) throws XPathExpressionException { return (NodeList) XPathFactory.newInstance().newXPath().evaluate(expression, contextNode, XPathConstants.NODESET); } }