使用 Java DOM 解析器解析 XML 文件会导致:
[Fatal Error] os__flag_8c.xml:103:135: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
最佳答案
XML 文档中有一些字符是不允许使用的,即使您将数据封装在 CDATA block 中也是如此。
如果您生成了文档,则需要对其进行实体编码或 将其剥离。如果你有一个错误的文档,你应该在尝试解析它之前去掉这些字符。
在此线程中查看 dolmens 的答案:Invalid Characters in XML
他在哪里链接到这篇文章:http://www.w3.org/TR/xml/#charsets
基本上,0x20 以下的所有字符都是不允许的,除了 0x9 (TAB)、0xA (CR?)、0xD (LF?)
关于java - 无效的 XML 字符(Unicode : 0xc) was found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5742543/