XElement 无法加载带有重音字符的文件

发布于 2024-10-10 10:32:07 字数 595 浏览 1 评论 0原文

我有一个相当好奇的问题,使用 XElement 加载方法加载 html 文档(使用 HTML Tidy 检查格式良好),它对于英语文档绝对完美,但是转到法语和西班牙语文档时,我会看到一个XML 异常;

XML Exception
Invalid character in the given encoding. Line 23, position 43.

方法调用

XElement doc = XElement.Load("example1.html", LoadOptions.None);

html 文档的

<font face="Arial" size="3" color="#ffffff">
Le test <b> exemple français, qui devrait éventuellement être suivie d'un texte en langue espagnole. </ b>
</font>

Sniplet我意识到我的 HTML 没有在文件开头设置编码类型,有办法解决这个问题吗?

I have a rather curious problem, using the XElement load method to load in a html document (which is well formed checked with HTML Tidy), which work absolutely perfectly for English documents, however moving to French and Spanish docs I'm presented with an XML Exception;

XML Exception
Invalid character in the given encoding. Line 23, position 43.

The method call

XElement doc = XElement.Load("example1.html", LoadOptions.None);

Sniplet of the html document

<font face="Arial" size="3" color="#ffffff">
Le test <b> exemple français, qui devrait éventuellement être suivie d'un texte en langue espagnole. </ b>
</font>

I realise my HTML does not have an encoding type set at the start of the file, is there a way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-10-17 10:32:07

因为您没有使用 XDocument,所以无法设置字符编码,请改用它并设置编码 = UTF-8

http://msdn.microsoft.com/en-us/library/bb387063.aspx

because you're not using XDocument you can't set character encoding, use that instead and set encoding = UTF-8

http://msdn.microsoft.com/en-us/library/bb387063.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文