C#XmlDocument with XmlTextWriter" ISO-8859-1"不是编码汉字 [英] C# XmlDocument with XmlTextWriter "ISO-8859-1" is not encoding Kanji
问题描述
字符串结果 有?对于汉字而不是正确的编码。
MemoryStream mStream =
new MemoryStream ();
编码 enc = 编码 。< /跨度> <跨度> GetEncoding 跨度> <跨度>(跨度> <跨度>" ISO-8859-1" 跨度> <跨度>); 跨度> <跨度>
XmlTextWriter writer =
new XmlTextWriter ( mStream , enc );
doc 。 WriteTo ( 作家 );
writer 。 Flush ( );
mStream 。 冲洗 ();
mStream 。 职位 =
0 ;
StreamReader sReader =
new StreamReader ( mStream , enc );
字符串 formattedXML = sReader 。 ReadToEnd ();
The string result has ?? for the Kanji instead of the proper encoding.
MemoryStream mStream =
new MemoryStream();
Encoding enc = Encoding.GetEncoding("ISO-8859-1");
XmlTextWriter writer =
new XmlTextWriter(mStream,enc);
doc.WriteTo(writer);
writer.Flush();
mStream.Flush();
mStream.Position =
0;
StreamReader sReader =
new StreamReader(mStream, enc);
String formattedXML = sReader.ReadToEnd();
推荐答案
ISO-8859-1 是一个代码页,其中包含许多西欧语言和美国使用的"英语"字符和重音字符以及各种标点符号。
ISO-8859-1 is a code page that contains the 'english' characters and accented characters used in many West European languages and America along with various punctuation marks.
它不包括日语汉字字符所以任何尝试在ISO-8859-中编码日语1注定要失败。如果你的文字包含日文字符,你需要使用合适的日文编码或只需坚持使用Unicode(包含所有内容)。
It does not include Japanese kanji characters so any attempt at encoding Japanese in ISO-8859-1 is doomed to failure. If your text includes Japanese characters you need to use a suitable Japanese encoding or just stick to Unicode (which contains everything).
这篇关于C#XmlDocument with XmlTextWriter" ISO-8859-1"不是编码汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!