c#頁面
輸出一xml文檔在as裡邊讀取xml的值形成列表。
sing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Text;
using OperClass;
using System.Xml;
namespace wqwj.FlashUser
{
/// <summary>
/// FlashMessagelist 的摘要說明。擷取xml使用者短訊息資訊列表
/// </summary>
public class FlashMessagelist : System.Web.UI.Page
{
CommClass cc = new CommClass();
string userid="";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置使用者代碼以初始化頁面
//CreateGrid();
ShowXML();
}
#region 輸出xml
/// <summary>
/// 取出資料匯出xml
/// </summary>
public void ShowXML()
{ userid= Request.QueryString["uid"].ToString();//"7";
string sqlstr="select top 10 * from message where receiverid='"+userid+"' and type=0 and (delstate='00' or delstate='10') order by id desc";
DataSet ds = cc.getDS(sqlstr,"message");
XmlDocument xmldoc = new XmlDocument () ;//加入XML的聲明段落
string xml = "<?xml version=\"1.0\" encoding=\"GB2312\"?><list></list>";
xmldoc.LoadXml(xml);//加入聲明和一個根項目
if(ds.Tables[0].Rows.Count>0)
{
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
string g_id=ds.Tables[0].Rows[i]["id"].ToString().Trim();
string isread=ds.Tables[0].Rows[i]["isread"].ToString().Trim();
string ishf=ds.Tables[0].Rows[i]["ishf"].ToString().Trim();
string title=CommClass.strDecode(ds.Tables[0].Rows[i]["title"].ToString().Trim());
string content=CommClass.strDecode(ds.Tables[0].Rows[i]["content"].ToString().Trim());
string addtime=CommClass.interceptStr(ds.Tables[0].Rows[i]["addtime"].ToString(),0,10,false);
string uid=ds.Tables[0].Rows[i]["senderid"].ToString().Trim();
string nickname=cc.getDataOne("select nickname from users where blocknumber="+uid+"");
XmlElement xmlelem = xmldoc.CreateElement ("Messages") ;//建立元素
xmlelem.SetAttribute("m_id",g_id);
xmlelem.SetAttribute("m_uid",uid);
xmlelem.SetAttribute("m_title",title );
xmlelem.SetAttribute("m_nc",nickname);
xmlelem.SetAttribute("m_content",content);
xmlelem.SetAttribute("m_addtime",addtime);
xmldoc.DocumentElement.AppendChild(xmlelem);//把元素加入<list></list>標記中
}
}
Response.Write(xmldoc.InnerXml);
}
#endregion
#region Web Form設計器產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web Form設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支援所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
源碼下載