Java tutorial
//package com.java2s; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { private static XPathFactory xpathFactory; public static XPathExpression getXPath(String expression) { try { return getXPathFactory().newXPath().compile(expression); } catch (XPathExpressionException e) { throw new RuntimeException("Invalid XPath Expression " + expression, e); } } /** * Gets the XPath factory, creating it if necessary. * * @return the XPath factory. */ public static synchronized XPathFactory getXPathFactory() { if (xpathFactory == null) { xpathFactory = XPathFactory.newInstance(); } return xpathFactory; } }