XmlTextWriter输出xml到页面的问题
2008-07-29 00:28
471 查看
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
this.Response.Clear();
XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
xtw.WriteStartDocument(true);
xtw.WriteStartElement("data");
xtw.WriteAttributeString("dd", "xx");
xtw.WriteEndElement();
xtw.WriteEndDocument();
Response.End();
}
输出的结果不对。最后从网上看到少了两句:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
this.Response.Clear();
XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
xtw.WriteStartDocument(true);
xtw.WriteStartElement("data");
xtw.WriteAttributeString("dd", "xx");
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Flush();
xtw.Close();
Response.End();
}
经过测试, Flush和Close方法只要有其一就可以正常。最好应该是两个都要。真是郁闷,xmltextwriter竟然不能自己提交缓存。
另外需要注意Response.End()也不能缺少。
{
Response.ContentType = "text/xml";
this.Response.Clear();
XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
xtw.WriteStartDocument(true);
xtw.WriteStartElement("data");
xtw.WriteAttributeString("dd", "xx");
xtw.WriteEndElement();
xtw.WriteEndDocument();
Response.End();
}
输出的结果不对。最后从网上看到少了两句:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
this.Response.Clear();
XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 3;
xtw.WriteStartDocument(true);
xtw.WriteStartElement("data");
xtw.WriteAttributeString("dd", "xx");
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Flush();
xtw.Close();
Response.End();
}
经过测试, Flush和Close方法只要有其一就可以正常。最好应该是两个都要。真是郁闷,xmltextwriter竟然不能自己提交缓存。
另外需要注意Response.End()也不能缺少。
相关文章推荐
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
- SQL Server 2000 中的 Text 输出到页面的用法问题
- aspx页面上输出xml的问题
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
- 对象转为xml输出到页面,中文乱码问题
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
- 【Servlet】Response的OutputStream与Writer输出数据乱码的问题
- 关于.text中AdvancedPanel中展开按钮在页面执行时有时会出错的问题
- C# XmlTextWriter和XmlTextReader 读写XML文件
- base64编码解码-解决xml输出转义问题
- 使用XmlTextWriter对象创建XML文件
- Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/
- Web程序中利用web.config解决无法输出excel页面的问题
- Python2.6.6的ElementTree输出xml中汉字变成&#xxxx的问题
- "响应消息的内容类型 text/html; charset=utf-8 与绑定(text/xml; charset=utf-8)的内容类型不匹配。"问题的解决办法
- Linux 下安装 xdebug及xdebug报错页面彩色格式化输出问题
- XmlTextWriter.WriteString与WriteRaw的区别
- MVC 4 Web API 输出Json 和xml的问题
- 编写XML XmlTextWriter与XmlDocument