question: public static String removeInvalidCharacterDataChars ( String s ) { boolean hasInvalidChars = false ; int length = s . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( ! isValidCharacterDataChar ( s . charAt ( i ) ) ) { hasInvalidChars = true ; break ; } } if ( hasInvalidChars ) { StringBuilder buffer = new StringBuilder ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { char c = s . charAt ( i ) ; if ( isValidCharacterDataChar ( c ) ) { buffer . append ( c ) ; } } return buffer . toString ( ) ; } else { return s ; } }
target:  Removes all non-valid XML character data chars from the specified String. If all characters are valid character data chars, this method will return the same String.