当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net下DataSet.WriteXml(String)与(Stream)的区别

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 asp.net下DataSet.WriteXml(String)与(Stream)的区别


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 261 ::
收藏到网摘: n/a

DataSet.WriteXml(String)生成的Xml文件中包含XML 声明, 而DataSet.WriteXml(Stream)却不会写入Xml声明即<?xml version="1.0" standalone="yes"?>
详细情况:
在写博客园的数据备份程序时,本来想通过ds.WriteXml(Response.OutputStream)直接将Xml数据发送到客户端,可是这样在客户端得到的Xml文件中的所有中文全是乱码,乱码的Xml文件与正常的Xml文件区别就是少了一行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();