当前位置: 代码迷 >> ASP.NET >> ~XmlWriterSettings 设置 XmlWriter的BOM头无效 Encoding设置无效
  详细解决方案

~XmlWriterSettings 设置 XmlWriter的BOM头无效 Encoding设置无效

热度:4739   发布时间:2013-02-25 00:00:00.0
救命啊~~XmlWriterSettings 设置 XmlWriter的BOM头无效 Encoding设置无效

XmlWriterSettings   settings   =   new   XmlWriterSettings();
settings.Encoding   =   Encoding.UTF8;
StringBuilder   sbXML   =   new   StringBuilder();
using   (XmlWriter   writer   =   XmlWriter.Create(sbXML,   settings))
{
              string   str   =   writer.Settings.Encoding.EncodingName;   //str是Unicode
              writer.WriteStartElement( "ajaxresponse ");
                    ...

              writer.Flush();
              writer.Close();
              Response.AddHeader( "Content-Type ",   "text/xml ");
              Response.Write(sbXML.ToString());

这样我最后输出到页面后的头部是
<?xml   version= "1.0 "   encoding= "utf-16 "?>
而我想要得到
<?xml   version= "1.0 "   encoding= "utf-8 "?>
大哥们救命   为什么设置无效   问题出哪了...

------解决方案--------------------------------------------------------
沙发沙发,帮忙顶

------解决方案--------------------------------------------------------
用replace()替换掉,然后再生成
  相关解决方案