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.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public static Node findNode(Document doc, String xpath) { return (Node) xpathFind(doc, xpath, XPathConstants.NODE); } public static Object xpathFind(Document doc, String xpath, QName returnType) { try { XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpathToolkit = xpathFactory.newXPath(); XPathExpression xpathExpression = xpathToolkit.compile(xpath); return xpathExpression.evaluate(doc, returnType); } catch (Exception e) { throw new RuntimeException("Error finding nodes for <" + xpath + ">", e); } } }