Java tutorial
//package com.java2s; // under the terms of the GNU General Public License as published by the import org.w3c.dom.*; import javax.xml.xpath.*; public class Main { public static Element SelectSingleElement(Element parent, String expression) { Element element = null; XPath xpath = getXPath(); try { XPathExpression xpathExpression = xpath.compile(expression); element = (Element) xpathExpression.evaluate(parent, XPathConstants.NODE); } catch (Exception e) { throw new RuntimeException(e); } return element; } public static XPath getXPath() { return getXPathFactory().newXPath(); } public static XPathFactory getXPathFactory() { return XPathFactory.newInstance(); } }