As w3c describe the valid chars for XML is limited.
We can recognize invalid char by following regular expression:
/*
* From xml spec valid chars:
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
*/
Pattern pattern = Pattern.compile("[^\\x09\\x0A\\x0D\\x20-\\xD7EF\\xE000-\\xFFFD\\x10000-x10FFFF]");
But I dont know why the expression isn't :
Pattern pattern = Pattern.compile("[^\\x09\\x0A\\x0D\\x20-\\xD7EF\\xE000-\\xFFFD\\x10000-\\x10FFFF]");
The error message is :
java.util.regex.PatternSyntaxException: Illegal character range near index 49
[^\x09\x0A\x0D\x20-\xD7EF\xE000-\xFFFD\x10000-\x10FFFF]