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 getNodesByXPath(Node node, String xpathStr) { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr; try { expr = xpath.compile(xpathStr); NodeList favoris = (NodeList) expr.evaluate(node, XPathConstants.NODESET); return favoris; } catch (XPathExpressionException e) { e.printStackTrace(); } return null; } }