private static String validateXML(String string) throws IOException {
  for (int i=0; i < string.length(); i++) {
    char ch=string.charAt(i);
    if (!(ch == 9 || ch == 10 || ch == 13 || ch >= 32))     throw new IOException("Character reference \"&#" + Integer.toString(ch) + "\" is an invalid XML character.");
  }
  return string;
}

private static String validateXML ( String string ) throws IOException { for ( int i = 0 ; i < string . length ( ) ; i ++ ) { char ch = string . charAt ( i ) ; if ( ! ( ch == 9 || ch == 10 || ch == 13 || ch >= 32 ) ) throw new IOException ( "Character reference \"&#" + Integer . toString ( ch ) + "\" is an invalid XML character." ) ; } return string ; }
validates whether the given string only contains valid xml characters .
