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();
}

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 ( ) ; }
replacing illegal xml char with entity ref
