Java tutorial
//package com.java2s; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { /** * Returns an {@link javax.xml.xpath.XPathExpression} from a string. * * @param xpathString the XPath string * @return the {@link javax.xml.xpath.XPathExpression} * @throws XPathExpressionException if the given XPath expression is incorrect */ public static XPathExpression getXPathExpression(String xpathString) throws XPathExpressionException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); return xpath.compile(xpathString); } }