它说xml有无效字符,然后找一下,xml 的无效字符有那些,它有三段,官方定义的无效字符为:
- 0x00 - 0x08
- 0x0b - 0x0c
- 0x0e - 0x1f
1:
str.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", "");
2:
public static String filter(String xmlStr) {
StringBuilder sb = new StringBuilder();
char[] chs = xmlStr.toCharArray();
// System.out.println("filter before=" +chs.length);
for (char ch : chs) {
if ((ch >= 0x00 && ch <= 0x08) || (ch >= 0x0b && ch <= 0x0c)
|| (ch >= 0x0e && ch <= 0x1f)) {
} else {
sb.append(ch);
}
}
// System.out.println("filter after=" +sb.length());
return sb.toString();
}