Here you can find the source of executeXPathExpression(Document document, String expression)
public static NodeList executeXPathExpression(Document document, String expression)
//package com.java2s; //License from project: Open Source License import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class Main { public static NodeList executeXPathExpression(Document document, String expression) { NodeList nodeList = null; XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr;//from w w w. j a va2s .co m try { expr = xpath.compile(expression); nodeList = (NodeList) expr.evaluate(document, XPathConstants.NODESET); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } return nodeList; } }