我有一个包含重音字符的 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>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 C# 代码读取这个 XML 文件时,我得到:
5/8/2013 2:39:03 PM 错误:System.Xml.XmlException:给定编码中的字符无效。第 86 行,位置 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'?>
Run Code Online (Sandbox Code Playgroud)
编辑
编码声明标识了使用哪种编码来表示 XML 文档中的字符。尽管 XML 解析器可以自动确定文档是使用 UTF-8 还是 UTF-16 Unicode 编码,但应在支持其他编码的文档中使用此声明。