【发布时间】:2012-02-08 13:20:18
【问题描述】:
我有一个可以序列化类型的自定义 xml 序列化程序,方法签名是:
string result = CustomXmlSerializer.Serialize(someObject);
序列化的结果我想让它在网页中可用,例如:
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=\"somefilename.xml\"");
Response.BufferOutput = true;
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "text/xml; encoding=utf-8";
string content= CustomXmlSerialize.Serialize(someObject);
byte[] utf8Bytes = Encoding.UTF8.GetBytes(content);
Response.OutputStream.Write(utf8Bytes, 0, utf8Bytes.Length);
Response.End();
但是生成的 xml 仍然有字符串内存编码(utf-16)?这怎么可能?我正在给HttpResponse写一个字节数组,编码为utf-8?
【问题讨论】:
-
也许你应该将 xml 添加到标签中
-
生成的文件是正确的,但是它有 应该是
标签: c# xml serialization encoding