public static String getXMLValidString ( final String input , final boolean replace , final char replacement ) { if ( input == null ) { return null ; } if ( "" . equals ( input ) ) { return "" ; } StringBuilder sb = new StringBuilder ( ) ; for ( char c : input . toCharArray ( ) ) { if ( XMLStringUtil . isXMLValid ( c ) ) { sb . append ( c ) ; } else if ( replace ) { sb . append ( replacement ) ; } } return sb . toString ( ) ; }
Remove or replace XML invalid chars from input .