Here you can find the source of evalXPath(Node node, String xPath)
public static List<Node> evalXPath(Node node, String xPath)
//package com.java2s; //License from project: BSD License import java.util.ArrayList; import java.util.List; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static XPath xpath = XPathFactory.newInstance().newXPath(); public static List<Node> evalXPath(Node node, String xPath) { synchronized (xpath) { try { NodeList nodes = (NodeList) xpath.evaluate(xPath, node, XPathConstants.NODESET); int size = nodes.getLength(); ArrayList<Node> list = new ArrayList<Node>(size); for (int i = 0; i < size; i++) list.add(nodes.item(i)); return list; } catch (XPathExpressionException e) { throw new RuntimeException("Invalid XPath expression:" + xPath); }//from w w w . j a v a 2s .c o m // InputSource inputSource = new InputSource("myXMLDocument.xml"); } } }