字符引用“”是无效的 XML 字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5869191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 14:41:03  来源:igfitidea点击:

Character reference "&#x1F" is an invalid XML character

xml

提问by perumal

Can anyone please tell me how to solve the following XML Exception?

谁能告诉我如何解决以下 XML 异常?

Character reference &#x1F is an invalid XML character

I have a XML file with the character &#x1F, When I try to parse this XML file I'm getting this Exception. Is there any way to resolve this?

我有一个带有  字符的 XML 文件,当我尝试解析这个 XML 文件时,我收到了这个异常。有没有办法解决这个问题?

The part of my code is like this...

我的代码部分是这样的......

File f = new File("sample.xml");
dom = db.parse(f);

I'm getting exception when I'm calling the function parse(). I also tried with UTF8 encoding, and got the same exception.

我在调用函数时遇到异常parse()。我也尝试过 UTF8 编码,但得到了同样的异常。

Any help is much appreciated.

任何帮助深表感谢。

Thank u in advance!!!

提前谢谢你!!!

回答by rwitzel

As Michael Kay commented: There are more valid characters in XML 1.1 than in XML 1.0. In case the XML has a prolog that declares version 1.0 it might be sufficient to change the prolog from

正如 Michael Kay 评论的那样:XML 1.1 中的有效字符比 XML 1.0 中的多。如果 XML 有一个声明版本 1.0 的序言,那么将序言从

<?xml version="1.0" >

to

<?xml version="1.1" >

If there are still invalid characters, you must decide how to deal with them. Streamflyerwill ease your task.

如果仍然存在无效字符,则必须决定如何处理它们。Streamflyer将减轻您的任务。

回答by oliverwood

You can create a class that extends FilterReader to skip invalid XML characters. See this link.

您可以创建一个扩展 FilterReader 的类以跳过无效的 XML 字符。请参阅此链接

回答by Ernest Friedman-Hill

The XML file is invalid, and the parser is telling you so. The control character decimal 31, hex 0x1F, can't appear in XML source. You need to have a look at the file and see what's going on.

XML 文件无效,解析器会告诉您无效。控制字符十进制 31,十六进制 0x1F,不能出现在 XML 源中。您需要查看该文件,看看发生了什么。

回答by Steve Wellens

Here is a list a valid character entities. Perhaps from the context of your xml you can determine what it should be:

这是一个有效字符实体的列表。也许从你的 xml 的上下文中你可以确定它应该是什么:

http://www.i18nguy.com/markup/ncrs.html

http://www.i18nguy.com/markup/ncrs.html