2
我有一個自定義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)?這怎麼可能?我正在給編碼爲utf-8的字節數組寫入HttpResponse
?
也許你應該添加xml到你的標籤 – 2012-02-08 13:23:27
生成的文件是正確的,但它有<?xml version =「1.0」encoding =「utf-16」?>它應該是<編碼=「utf-8」 > – Elena 2012-02-08 13:26:07