Java tutorial
//package com.java2s; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public static Node selectSingleNode(Node refNode, String expression) { XPath xPath = XPathFactory.newInstance().newXPath(); Node outNode = null; try { outNode = (Node) xPath.compile(expression).evaluate(refNode, XPathConstants.NODE); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } return outNode; } public static Node selectSingleNode(Document refNode, String expression) { XPath xPath = XPathFactory.newInstance().newXPath(); Node outNode = null; try { outNode = (Node) xPath.compile(expression).evaluate(refNode, XPathConstants.NODE); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } return outNode; } }