public static String replaceXmlAttr ( final String xml , final KV ... keyValues ) { final List < String > searchList = new ArrayList < String > ( ) ; final List < String > replacementList = new ArrayList < String > ( ) ; for ( final KV kv : keyValues ) { final String tag = kv . getKey ( ) + "=\"" ; int pa = xml . indexOf ( tag ) ; while ( pa > - 1 ) { final int s = pa + tag . length ( ) ; final int pe = xml . indexOf ( "\"" , s ) ; if ( pe > - 1 ) { final String str = xml . substring ( pa , pe + 1 ) ; searchList . add ( str ) ; final String repl = xml . substring ( pa , pa + tag . length ( ) ) + kv . getValue ( ) + "\"" ; replacementList . add ( repl ) ; } pa = xml . indexOf ( tag , s ) ; } } final String [ ] searchArray = searchList . toArray ( new String [ searchList . size ( ) ] ) ; final String [ ] replacementArray = replacementList . toArray ( new String [ replacementList . size ( ) ] ) ; return StringUtils . replaceEachRepeatedly ( xml , searchArray , replacementArray ) ; }
Replaces the content of one or more XML attributes .