Dom4j 讀 xml 時,遇到 xml 無效字元,報錯:An invalid XML character
它說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();
}
相關文章
- Java - XML字元支援報錯An invalid XML characterJavaXML字元
- Error parsing XML: An invalid XML character (Unicode:0x1f) was foundErrorXMLUnicode
- SAXParseException An invalid XML character 問題的解決ExceptionXML
- 解決XML下無效字元的問題XML字元
- 解析XML檔案時,無效的XML 字元 (Unicode: 0x7)異常處理XML字元Unicode
- An invalid XML character (Unicode: 0x18) was foundXMLUnicode
- Dom4j 讀寫XML簡介XML
- dom4j讀寫xml檔案XML
- DOM4J 解析 XML 之忽略轉義字元XML字元
- dom4j解析xmlXML
- Dom4j 操作 XMLXML
- dom4j 讀取網路的xmlXML
- xml中有特殊字元,導致解析時出錯XML字元
- Jsp Unescaped xml character報錯的解決辦法JSXML
- 對XML 進行 parse 時的Invalid Unicode character (0x0) 分析XMLUnicode
- An invalid XML character (Unicode: 0x10) was found in the value of attributeXMLUnicode
- An invalid XML character (Unicode: 0x4) was found in the element content of theXMLUnicode
- All About JAVA An invalid XML character (Unicode: 0xdd65) was found in the comment 錯誤JavaXMLUnicode
- 微信公眾號 報 An invalid XML character (Unicode: 0x1a) was found in the CDATA sectioXMLUnicode
- 使用dom4j 解析, 操作XMLXML
- Dom4j解析XML資料XML
- 使用Dom4j解析XML案例XML
- 讀取xml檔案 解析雙層xmlXML
- java學習:使用dom4j讀寫xml檔案JavaXML
- dom4j遍歷巢狀xml巢狀XML
- XML 程式設計思想: 研讀XML Hacks(轉)XML程式設計
- 序列化篇 生成xml 以及讀取xmlXML
- Unity 讀取xmlUnityXML
- java的XML解析(DOM4J技術)JavaXML
- Java DOM4J 方式解析XML檔案JavaXML
- 用dom4j,解析xml 最好、最方便!XML
- 利用dom4j來生成xml檔案XML
- C#基礎系列:Linq to Xml讀寫xmlC#XML
- xml問題請教:org.xml.sax.SAXParseException: Invalid encoding name "GBK".XMLExceptionEncoding
- Python xml.etree.ElementTree讀寫xml檔案例項PythonXML
- C#讀取XMLC#XML
- C# 讀寫xmlC#XML
- XML namespace problems with IBM JDK(xml在使用ibm jdk時解釋錯誤)XMLnamespaceIBMJDK