Java tutorial
//package com.java2s; import javax.xml.namespace.QName; import javax.xml.xpath.XPath; 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 Object evalXPathExpr(String pathExpr, Document xmlDocument, QName returnType) { XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpathObj = xPathFactory.newXPath(); XPathExpression expr; Object result = null; try { expr = xpathObj.compile(pathExpr); result = expr.evaluate(xmlDocument, returnType); } catch (XPathExpressionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return result; } }