Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.w3c.dom.Node; 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 Node selectSingleNode(Document xmlDocument, String expression) throws XPathExpressionException { return (Node) selectObject(xmlDocument, expression, XPathConstants.NODE); } public static Object selectObject(Document xmlDocument, String expression, QName returnType) throws XPathExpressionException { XPath xPath = XPathFactory.newInstance().newXPath(); return xPath.compile(expression).evaluate(xmlDocument, returnType); } }