asp.net下DataSet.WriteXml(String)與(Stream)的區(qū)別
更新時間:2007年04月13日 00:00:00 作者:
DataSet.WriteXml(String)生成的Xml文件中包含XML 聲明, 而DataSet.WriteXml(Stream)卻不會寫入Xml聲明即<?xml version="1.0" standalone="yes"?>
詳細情況:
在寫博客園的數據備份程序時,本來想通過ds.WriteXml(Response.OutputStream)直接將Xml數據發(fā)送到客戶端,可是這樣在客戶端得到的Xml文件中的所有中文全是亂碼,亂碼的Xml文件與正常的Xml文件區(qū)別就是少了一行Xml聲明。然后, 我改了代碼, 手動寫入Xml聲明, 亂碼問題就解決,代碼如下:
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
詳細情況:
在寫博客園的數據備份程序時,本來想通過ds.WriteXml(Response.OutputStream)直接將Xml數據發(fā)送到客戶端,可是這樣在客戶端得到的Xml文件中的所有中文全是亂碼,亂碼的Xml文件與正常的Xml文件區(qū)別就是少了一行Xml聲明。然后, 我改了代碼, 手動寫入Xml聲明, 亂碼問題就解決,代碼如下:
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
相關文章
使用 .NET MAUI 開發(fā) ChatGPT 客戶端的流程
最近?chatgpt?很火,由于網頁版本限制了 ip,還得必須開代理,用起來比較麻煩,所以我嘗試用 maui 開發(fā)一個聊天小應用,結合 chatgpt 的開放 api 來實現(xiàn),這篇文章主要介紹了使用 .NET MAUI 開發(fā) ChatGPT 客戶端,需要的朋友可以參考下2022-12-12
.NET Core3.0創(chuàng)建Worker Services的實現(xiàn)
這篇文章主要介紹了.NET Core3.0創(chuàng)建Worker Services的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10
asp.net AutoCompleteExtender的一個簡單例子代碼
asp.net AutoCompleteExtender的一個簡單例子代碼2009-12-12
Silverlight中動態(tài)獲取Web Service地址
開發(fā)過Silverlight應用的朋友們相信都會遇到這樣一個問題2009-11-11
解決VS2012 Express的There was a problem sending the command to
安裝Visual Studio 2012 Express之后,雙擊打開web.config文件時經常出現(xiàn)“There was a problem sending the command to the program”的錯誤,然后VS2012 Express打開了,但web.config文件沒打開,需要再次雙擊web.config文件才能打開。很是煩人2013-02-02

