XPathUtils { public static String replaceDynamicNamespaces(String expression, Map<String, String> namespaces) { String expressionResult = expression; for (Entry<String, String> namespaceEntry : namespaces.entrySet()) { if (expressionResult.contains(DYNAMIC_NS_START + namespaceEntry.getValue() + DYNAMIC_NS_END)) { expressionResult = expressionResult.replaceAll("\\" + DYNAMIC_NS_START + namespaceEntry.getValue().replace(".", "\\.") + "\\" + DYNAMIC_NS_END, namespaceEntry.getKey() + ":"); } } return expressionResult; } private  XPathUtils(); static Map<String, String> getDynamicNamespaces(String expression); static String replaceDynamicNamespaces(String expression, Map<String, String> namespaces); static boolean hasDynamicNamespaces(String expression); static Object evaluate(Node node, String xPathExpression,
            NamespaceContext nsContext, XPathExpressionResult resultType); static Node evaluateAsNode(Node node, String xPathExpression, NamespaceContext nsContext); static NodeList evaluateAsNodeList(Node node, String xPathExpression, NamespaceContext nsContext); static String evaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext); static Boolean evaluateAsBoolean(Node node, String xPathExpression, NamespaceContext nsContext); static Double evaluateAsNumber(Node node, String xPathExpression, NamespaceContext nsContext); static Object evaluateAsObject(Node node, String xPathExpression, NamespaceContext nsContext, QName resultType); static boolean isXPathExpression(String expression); static Object evaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType); static final String DYNAMIC_NS_START; static final String DYNAMIC_NS_END; }
@Test public void testDynamicNamespaceReplacement() { Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("ns1", "http: namespaces.put("ns2", "http: namespaces.put("ns3", "http: Assert.assertEquals(XPathUtils.replaceDynamicNamespaces(" " Assert.assertEquals(XPathUtils.replaceDynamicNamespaces(" " Assert.assertEquals(XPathUtils.replaceDynamicNamespaces(" " Assert.assertEquals(XPathUtils.replaceDynamicNamespaces(" " }