Java tutorial
//package com.java2s; import javax.xml.xpath.*; import org.w3c.dom.Node; public class Main { private static XPathFactory xpathFactory = null; private static XPath xpath = null; /** * This method uses XPath to get you a child node of the provided node. * @param parentNode The node to start at. * @param expression The XPath Expression to evaluate. * @return The Node that was retrieved by the provided node and xpath expression. * @throws XPathExpressionException * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ public static Node getNode(Node parentNode, String expression) throws XPathExpressionException { return (Node) getXPath().evaluate(expression, parentNode, XPathConstants.NODE); } /** * This method gives you an XPath object from the XPath Factory. * @return A new XPath object. * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ protected static synchronized XPath getXPath() { if (xpath == null) { xpath = getXPathFactory().newXPath(); } return xpath; } /** * This method yields the XPath Factory (creating it if necessary). * @return The XPathFactory object. * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ protected static synchronized XPathFactory getXPathFactory() { if (xpathFactory == null) { xpathFactory = XPathFactory.newInstance(); } return xpathFactory; } }