XElement 无法加载带有重音字符的文件
我有一个相当好奇的问题,使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您没有使用 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