Java tutorial
//package com.java2s; import javax.xml.namespace.QName; 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; public class Main { public static Node nodeForXPath(Node node, String xPathString) throws XPathExpressionException { QName returnType = XPathConstants.NODE; return (Node) getXPath(node, xPathString, returnType); } public static Object getXPath(Node node, String xPathString, QName returnType) throws XPathExpressionException { XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); XPathExpression expression = xPath.compile(xPathString); return expression.evaluate(node, returnType); } }