Java tutorial
//package com.java2s; import javax.xml.namespace.QName; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Node; public class Main { public static Node selectNode(String xpath, Object node) { return (Node) evaluateXPath(xpath, node, XPathConstants.NODE); } public static Object evaluateXPath(String xpath, Object item, QName returnType) { try { return XPathFactory.newInstance().newXPath().compile(xpath).evaluate(item, returnType); } catch (XPathExpressionException e) { throw new IllegalArgumentException(e); } } }