c# - 无法打开/读取包含重音字符的 XML 文件

标签 c# xml

我有一个包含重音字符的 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/

相关文章:

c# - 如何调用函数序列?

android - 重用 XML 组件,仅更改一个文本字段

xml - 马克逻辑 8 : Cannot load a XML document to MarkLogic database using cURL

java - Android Studio/Java/XML 中的 "Unbound Prefix"是什么?

c# - NLog xsi :type not working with custom target

c# - 确定性处理 ThreadStatic 对象

c# - 匹配 2 个具有相同实例名称的不同对象

java - XML 处理 - 性能问题

java - RecyclerView 的奇怪行为

c# - 为什么多次调用 GC.Collect() 会释放一些通常不会清理的内存?