Java tutorial
//package com.java2s; 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 final XPathFactory XPATH_FACTORY = XPathFactory.newInstance(); /** * Returns the DOM nodes associated to a given xpath expression. * * @param node The root DOM node * @param xpath The xpath expression * @return The extracted DOM nodes * @throws XPathExpressionException If the given xpath expression is invalid */ public static NodeList getNodes(Node node, String xpath) throws XPathExpressionException { return (NodeList) XPATH_FACTORY.newXPath().evaluate(xpath, node, XPathConstants.NODESET); } }