如何告诉Java SAX解析器忽略无效的字符引用? [英] How to tell Java SAX Parser to ignore invalid character references?
问题描述
当使用诸如&#x1
的字符参考来解析不正确的XML时,Java的SAX解析器会死亡,造成致命的错误,例如
When trying to parse incorrect XML with a character reference such as 
, Java's SAX Parser dies a horrible death with a fatal error such as
org.xml.sax.SAXParseException: Character reference ""
is an invalid XML character.
有没有办法呢?在将其移交给SAX解析器之前,我必须清理XML文件吗?如果是这样,有没有一个优雅的方式来解决这个问题?
Is there any way around this? Will I have to clean up the XML file before I hand it off to the SAX Parser? If so, is there an elegant way of going about this?
推荐答案
使用XML 1.1! skaffman是完全正确的,但您可以在文件顶部粘贴<?xml version =1.1?>
,您将处于良好状态。如果您正在处理流,请写一个重写或添加处理指令的包装器。
Use XML 1.1! skaffman is completely right, but you can just stick <?xml version="1.1"?>
on the top of your files and you'll be in good shape. If you're dealing with streams, write a wrapper that rewrites or adds that processing instruction.
这篇关于如何告诉Java SAX解析器忽略无效的字符引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!