的XElement无法加载文件重音字符 [英] XElement fails to load file with accented characters

查看:217
本文介绍了的XElement无法加载文件重音字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当奇怪的问题,使用的XElement load方法在一个HTML文件来加载(这是中规中矩检查了HTML精简),它绝对完美地工作的英文文件,但转移到法语和西班牙语文档我presented与XML异常;

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.

方法调用

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

在HTML文档的Sniplet

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>

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

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

推荐答案

因为你不使用的XDocument不能设置字符编码,使用并设置编码= UTF-8

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

这篇关于的XElement无法加载文件重音字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆