XPathUtils { public static Map<String, String> getDynamicNamespaces(String expression) { Map<String, String> namespaces = new HashMap<String, String>(); if (expression.contains(DYNAMIC_NS_START) && expression.contains(DYNAMIC_NS_END)) { String[] tokens = expression.split("\\" + DYNAMIC_NS_START); for (int i = 1; i < tokens.length; i++) { String namespace = tokens[i].substring(0, tokens[i].indexOf(DYNAMIC_NS_END)); if (!namespaces.containsValue(namespace)) { namespaces.put(DYNAMIC_NS_PREFIX + i, namespace); } } } return namespaces; } 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 testDynamicNamespaceCreation() { Map<String, String> namespaces; namespaces = XPathUtils.getDynamicNamespaces(" Assert.assertEquals(namespaces.size(), 1); Assert.assertEquals(namespaces.get("dns1"), "http: namespaces = XPathUtils.getDynamicNamespaces(" Assert.assertEquals(namespaces.size(), 2); Assert.assertEquals(namespaces.get("dns1"), "http: Assert.assertEquals(namespaces.get("dns2"), "http: namespaces = XPathUtils.getDynamicNamespaces(" Assert.assertEquals(namespaces.size(), 3); Assert.assertEquals(namespaces.get("dns1"), "http: Assert.assertEquals(namespaces.get("dns2"), "http: Assert.assertEquals(namespaces.get("dns3"), "urn:citrus"); }