我有一个包含重音字符的 XML 属性:
<TestCase Name="Canadian Addresses - Test Case" Description="Canadian Addresses - Test Case" OnOff="True" NegativeTest="False" RollbackDB="False" Performance="False" PerformanceSummary="False" TimesToExecute="1">
<ProviderFacilitySearch_FindProviderFacility ProviderInfo="Dr Marc-André Kärcher Samuels Senior|10 Château du Feÿ Ave, North Building, North Sydney, NS B2A 3L7 CANADA" />
<ProviderFacilitySearch_ViewProviderFacility ProviderInfo="Dr Marc-André Kärcher Samuels Senior|10 Château du Feÿ Ave, North Building, North Sydney, NS B2A 3L7 CANADA" />
<ViewProvider_LocationName ExpectedLocationName="Kärcher Health Care" />
<ViewProvider_ServicingAddress ExpectedServicingAddress="10 Château du Feÿ Ave|Central Building|North Sydney, NS B2A 3L7|CANADA" />
<ViewProvider_ExpandMailingAddress NA="" />
<ViewProvider_MailingAddress ExpectedMailingAddress="10 Château du Feÿ Ave|Central Building|North Sydney, NS B2A 3L7|CANADA" />
<ViewProvider_ExpandBillingAddress NA="" />
<ViewProvider_BillingAddress ExpectedBillingAddress="10 Château du Feÿ Ave|Central Building|North Sydney, NS B2A 3L7|CANADA" />
<ViewProvider_Close NA="" />
<ProviderFacilitySearch_Cancel NA="" />
<UserLogout/>
</TestCase>
当我尝试使用 C# 代码读取此 XML 文件时,我得到:
5/8/2013 2:39:03 PM ERROR: System.Xml.XmlException: Invalid character in the given encoding. Line 86, position 74. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
我什至无法使用 IE 打开该页面。
有没有办法让这项工作成功?
最佳答案
使用这个标题:
<?XML VERSION='1.0' ENCODING='ISO-8859-1'?>
编辑
编码声明标识了使用哪种编码来表示 XML 文档中的字符。尽管 XML 解析器可以自动确定文档是使用 UTF-8 还是 UTF-16 Unicode 编码,但应该在支持其他编码的文档中使用此声明。
关于c# - 无法打开/读取包含重音字符的 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16447970/