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()替换掉,然后再生成