如何从数据库里面的数据显示在页面上是XML格式的?做API接口是这样么?
.net开发,我现在要做一个API接口,要把数据库取出来的值显示成XML格式在页面上面,请各位大侠帮帮忙~!
[解决办法]
http://blog.csdn.net/greatfeather/article/details/2585701
[解决办法]
简单的XML输出
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Xml;using System.IO;using System.Text;public partial class Ajax_check_etao :PowerEasy.SiteFactory.Web.UI.BasePage{ public XmlTextWriter XmlResponseWriter; protected void Page_Load(object sender, EventArgs e) { base.Response.Clear(); base.Response.Buffer = true; base.Response.Charset = "utf-8"; base.Response.AddHeader("contenttype", "text/xml"); base.Response.ContentEncoding = Encoding.GetEncoding("utf-8"); base.Response.ContentType = "text/xml"; XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 4; this.XmlResponseWriter = writer; this.XmlResponseWriter.WriteStartDocument(); this.XmlResponseWriter.WriteStartElement("root", ""); XmlTextWriter XmlResponseWriter = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8); if (Session["etao_name"] == null || Session["etao_name"].ToString()=="") { this.XmlResponseWriter.WriteElementString("status", "no"); } else { this.XmlResponseWriter.WriteElementString("status", "yes"); this.XmlResponseWriter.WriteElementString("username", Session["etao_name"].ToString()); } this.XmlResponseWriter.WriteEndElement(); this.XmlResponseWriter.WriteEndDocument(); this.XmlResponseWriter.Close(); base.Response.End(); return; }}