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.Document; public class Main { public static String evaluateToString(Document document, String expression) throws XPathExpressionException { return (String) evaluate(document, expression, XPathConstants.STRING); } public static Object evaluate(Document document, String expression, QName returnType) throws XPathExpressionException { XPathExpression xpathexp = getXPathExpression(expression); return xpathexp.evaluate(document, returnType); } public static XPathExpression getXPathExpression(String expression) throws XPathExpressionException { return getXPathInstance().compile(expression); } public static XPath getXPathInstance() { XPath xPath = XPathFactory.newInstance().newXPath(); return xPath; } }