Java dom读取XML文件中特殊字符-报错

来源:互联网 发布:新纪元软件下载 编辑:程序博客网 时间:2024/05/20 11:36

在用dom读取XML文件的时候,报错。

以下是错误:

[Fatal Error] A01.xml:6:53: The character reference must end with the ';' delimiter.Exception in thread "main" org.xml.sax.SAXParseException: The character reference must end with the ';' delimiter.  at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)  at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)  at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)  at Parser.Parse(Parser.java:108)  at Parser.main(Parser.java:185)

 

类似的XML内容

<title>Reduction Algorithm using the &#192 TROUS Wavelet Transform.</title>

 

解决方法:

遇到这样的特殊字符&#\d{1,4}[^;],

大家都应该替换一下:

String.replaceAll("&#192", "&#192;");