Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { public static String selectString(Document xmlDocument, String expression) throws XPathExpressionException { return (String) selectObject(xmlDocument, expression, XPathConstants.STRING); } public static Object selectObject(Document xmlDocument, String expression, QName returnType) throws XPathExpressionException { XPath xPath = XPathFactory.newInstance().newXPath(); return xPath.compile(expression).evaluate(xmlDocument, returnType); } }