asp.net输出纯xml格式数据
发布:liao | 发布时间: 2008年5月7日<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Server01.aspx.cs" Inherits="Server01" %>
只保留以上这行代码。
.cs文件主要是:
public partial class Server01 : System.Web.UI.Page

...{
private string connString = @"server=BJ2-JIANGFJFDBSERVER;Trusted_Connection=false;database=TestDB;uid=sa;pwd=7929009";


protected void Page_Load(object sender, EventArgs e)

...{
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";

getDataset();
// getXml();

Response.End();
}

private void getDataset()

...{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connString);

SqlCommand cmd = new SqlCommand("select * from TA",conn);

SqlDataAdapter sda = new SqlDataAdapter(cmd);

sda.Fill(ds);
DataTable dt = ds.Tables[0];

StringBuilder xmlData = new StringBuilder();
xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>");
xmlData.AppendLine(@"<root>");

foreach (DataRow dr in dt.Rows)

...{
string id = dr["id"].ToString();
string name = dr["name"].ToString();

xmlData.AppendLine(@"<person");
xmlData.AppendLine(@" id='"+id+"' ");
xmlData.AppendLine(@">");

xmlData.AppendLine(@"<id>" + id + "</id>");
xmlData.AppendLine(@"<name>" + name + "</name>");

xmlData.AppendLine(@"</person>");
}
xmlData.AppendLine(@"</root>");
Response.Write(xmlData.ToString());

}
private void getXml()

...{
StringBuilder xmlData = new StringBuilder();
xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>");
xmlData.AppendLine(@"<root>根节点</root>");
xmlData.AppendLine(@"根节点" + DateTime.Now.ToString() + "");
xmlData.AppendLine(@"</root>");

Response.Write(xmlData.ToString());
}
}
只保留以上这行代码。
.cs文件主要是:
public partial class Server01 : System.Web.UI.Page 
...{
private string connString = @"server=BJ2-JIANGFJFDBSERVER;Trusted_Connection=false;database=TestDB;uid=sa;pwd=7929009"; 

protected void Page_Load(object sender, EventArgs e) 
...{
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "UTF-8"; 
getDataset();
// getXml(); 
Response.End();
} 
private void getDataset() 
...{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connString); 
SqlCommand cmd = new SqlCommand("select * from TA",conn); 
SqlDataAdapter sda = new SqlDataAdapter(cmd); 
sda.Fill(ds);
DataTable dt = ds.Tables[0]; 
StringBuilder xmlData = new StringBuilder();
xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>");
xmlData.AppendLine(@"<root>"); 
foreach (DataRow dr in dt.Rows) 
...{
string id = dr["id"].ToString();
string name = dr["name"].ToString(); 
xmlData.AppendLine(@"<person");
xmlData.AppendLine(@" id='"+id+"' ");
xmlData.AppendLine(@">"); 
xmlData.AppendLine(@"<id>" + id + "</id>");
xmlData.AppendLine(@"<name>" + name + "</name>"); 
xmlData.AppendLine(@"</person>");
}
xmlData.AppendLine(@"</root>");
Response.Write(xmlData.ToString()); 
}
private void getXml() 
...{
StringBuilder xmlData = new StringBuilder();
xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>");
xmlData.AppendLine(@"<root>根节点</root>");
xmlData.AppendLine(@"根节点" + DateTime.Now.ToString() + "");
xmlData.AppendLine(@"</root>"); 
Response.Write(xmlData.ToString());
}
}
发布:liao | 分类:net技术 | 评论:0 | 引用:0 | 浏览:
| TrackBack引用地址
- 相关文章:
TreeView的用法 (2008-4-5 14:17:46)
Ajax无刷新实现图片切换特效 (2008-4-2 16:21:11)
ajaxpro在vs2005中应用 (2008-4-1 15:15:58)
asp.net导出excel (2008-3-21 10:54:38)
ASP.NET无限级分类的非递归实现(存储过程版) (2008-3-15 14:13:19)
asp.net反编译方法 (2008-3-13 11:53:10)
在ASP.NET中实现AJAX 3 (2008-3-9 23:24:25)
在ASP.NET中实现AJAX 2 (2008-3-9 23:23:17)
在ASP.NET中实现AJAX 1 (2008-3-9 23:20:58)
判断浏览器是否接受Cookies (2008-2-20 1:43:19)
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。





