XmlDocument.Load()方法无法解码€(欧元) [英] XmlDocument.Load() method fails to decode € (euro)

查看:166
本文介绍了XmlDocument.Load()方法无法解码€(欧元)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文档 file.xml ,它编码为Iso-latin-15(也称为Iso-Latin-9)

I have an XML document file.xml which is encoded in Iso-latin-15 (aka Iso-Latin-9)

<?xml version="1.0" encoding="iso-8859-15"?>
<root xmlns="http://stackoverflow.com/demo">
  <f>€.txt</f>
</root>

从我最喜欢的文本编辑器,我可以告诉这个文件在Iso-Latin-15它不是UTF-8)。

From my favorite text editor, I can tell this file is correctly encoded in Iso-Latin-15 (it is not UTF-8).

我的软件是用C#编写的,想要提取元素 f

My software is written in C# and wants to extract the element f.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("file.xml"); 

在现实生活中,我有一个XMLResolver设置凭据。但是基本上,我的代码很简单。载入顺利,我没有任何异常提出。

In real life, I have a XMLResolver to set credentials. But basically, my code is as simple as that. The loading goes smoothly, I don't have any exception raised.

现在,当我提取值时,我的问题:

Now, my problem when I extract the value:

//xnsm is the XmlNameSpace manager
XmlNode n = xmlDoc.SelectSingleNode("//root/f", xnsm); 
if (n != null)
  String filename = n.InnerText;

Visual Studio调试器显示文件名= □.txt

The Visual Studio debugger displays filename = □.txt

它只能是一个Visual Studio错误。不幸的是, File.Exists(filename)返回false,而文件实际存在。

It could only be a Visual Studio bug. Unfortunately File.Exists(filename) returns false, whereas the file actually exist.

怎么了? >

What's wrong?

推荐答案

不要使用调试器或控制台将字符串显示为一个字符串。

Don't just use the debugger or the console to display the string as a string.

而是一次转储字符串的内容,一个字符。例如:

Instead, dump the contents of the string, one character at a time. For example:

foreach (char c in filename)
{
    Console.WriteLine("{0}: {1:x4}", c, (int) c);
}

这将显示您的真实内容字符串,而不是受当前字体显示的限制。

That will show you the real contents of the string, in terms of Unicode code points, instead of being constrained by what the current font can display.

使用 Unicode代码图表来查找指定的字符。

Use the Unicode code charts to look up the characters specified.

这篇关于XmlDocument.Load()方法无法解码€(欧元)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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