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.Node; import org.w3c.dom.NodeList; public class Main { public static NodeList selectNodeList(Node node, String str) throws XPathExpressionException { XPathExpression xPathExpression = null; NodeList nList = null; synchronized (getXPathBuilder()) { xPathExpression = getXPathBuilder().compile(str); nList = (NodeList) xPathExpression.evaluate(node, XPathConstants.NODESET); } return nList; } public static XPath getXPathBuilder() { XPathFactory xpathfactory = XPathFactory.newInstance(); XPath xpath = xpathfactory.newXPath(); return xpath; } }