0

使用十六进制 0x19 字符 C# 读取 xml 文档

显然,上述字符在 C# 中无效,我即将加载的 XML 文档包含它。

因此,每次我尝试阅读它时都会引发 XML 异常。

<description><![CDATA[Whenever I run<br>Whenever I run to you lost one<br>Its never done<br>Just hanging on<br><br>Just past has let me be<br>Returning as if dream<br>Shattered as belief<br><br>If you have to go dont say goodbye<br>If you have to go dont you cry<br>If you have to go I will get by<br>Someday Ill follow you and see you on the other side<br><br>But for the grace of love<br>Id will the meaning of<br>Heaven from above<br><br>Your picture out of time<br>Left aching in my mind<br>Shadows kept alive<br><br>If you have to go dont say goodbye<br>If you have to go dont you cry<br>If you have to go I will get by<br>I will follow you and see you on the other side<br><br>But for the grace of love<br>Id will the meaning of<br>Heaven from above<br><br>Long horses we are born<br>Creatures more than torn<br>Mourning our way home]]></description>

显然上面的行包含那个字符

4

1 回答 1

1

刚遇到同样的问题。0x19 是一个控制字符(媒体结束),在文本编辑器中几乎不可见。无论如何,我解析 XML 的方法是在解析之前用空格替换这个字符,如下所示:

var xmlString = GetXmlString();
xmlString = xmlString.Replace((char)0x19, ' ');
var doc = new XmlDocument();
doc.LoadXml(xmlString);
于 2015-05-10T16:25:23.680 回答