/** * @param ns * @param xpathExpression * @return the parsed string as {@link XPathExpression} */ public static XPathExpression toExpression(Map<String, String> ns, String xpathExpression) { try { XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); if (ns.size() > 0) { xpath.setNamespaceContext(toNsContext(ns)); } XPathExpression expr = xpath.compile(xpathExpression); return expr; } catch (XPathExpressionException e) { throw new IllegalArgumentException( "xPath expression can not be compiled: " + xpathExpression, e); } }