question: private String replaceIllegalChar ( String data , char ch , String replacement ) { int idx = 0 ; StringBuilder buffer = new StringBuilder ( data . length ( ) * 4 ) ; while ( ( data != null ) && ( idx = data . indexOf ( ch ) ) != - 1 ) { buffer . append ( data . substring ( 0 , idx ) ) ; buffer . append ( replacement ) ; data = data . substring ( idx + 1 ) ; } if ( ( data != null ) && ( data . length ( ) > 0 ) ) { buffer . append ( data ) ; } return buffer . toString ( ) ; }
target:  Replacing illegal XML char with entity ref