XElement fails to load file with accented characters

て烟熏妆下的殇ゞ 提交于 2020-01-14 13:22:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4595041/xelement-fails-to-load-file-with-accented-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!