Java 解析XML文件错误。
错误信息提示代码类似如下:
The reference to entity "characterEncoding" must end with the ';' delimiter.
org.xml.sax.SAXParseException: The reference to entity "characterEncoding" must end with the ';' delimiter.
或
ontext initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The reference to entity "characterEncoding" must end with the ';' delimiter.
纠错结果:
我在配置一个访问数据库的Url时,第一次设置的内容如下:
jdbc:mysql://localhost:3306/photo?useUnicode=true&characterEncoding=UTF-8,注意中间那个“&”,在xml中这个是读不出的哦,那么应该怎么改呢?我采取了一个折衷的方法,不过真的可以了:
jdbc:mysql://localhost:3306/photo?useUnicode=true&characterEncoding=UTF-8
分析:
有时候在使用xml作为配置文件的时候,应该要使用xml的编码规则来进行适当的设置。
下面给出xml中一些特殊符号的编码转换:
| < | < | 小于号 |
| > | > | 大于号 |
| & | & | and字符 |
| ' | ' | 单引号 |
| " | " | 双引号 |
本文针对Java应用程序中出现的XML配置文件解析错误进行了详细说明,并提供了解决方案。具体错误为XML文档中的引用实体未以分号结尾。文章还介绍了如何正确配置数据库URL参数以及XML特殊字符的转义规则。
1169

被折叠的 条评论
为什么被折叠?



