Java tutorial
//package com.java2s; 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.Node; import org.w3c.dom.NodeList; public class Main { public static NodeList getNodeList(Document doc, String xPathAsString) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(xPathAsString); return (NodeList) expr.evaluate(doc, XPathConstants.NODESET); } public static NodeList getNodeList(Node node, String xPathAsString) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(xPathAsString); return (NodeList) expr.evaluate(node, XPathConstants.NODESET); } }