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 ; }
Replaces all dynamic namespaces in a XPath expression with respective prefixes in namespace map .