//aspx页面内容 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> //aspx.cs内容 using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; using System.Data; public partial class _Default : System.Web.UI.Page { //页面直接加载 protected void Page_Load(object sender, EventArgs e) { load(); } //单击加载 protected void imgBtn_Click(object sender, ImageClickEventArgs e) { load(); } private void load() { //创建xml bool b = LogWrite(Server.MapPath("~/web/RssMessage.xml")); //转到xml //Response.Redirect("web/RssMessage-2010-11-11.xml"); DataSet ds = new DataSet(); string data = Server.MapPath("~/web/RssMessage.xml").ToString(); if (b) { ds.ReadXml(data); string a = ds.GetXml(); Response.Clear(); Response.ContentType = "Text/XML"; Response.Expires = 0; Response.Cache.SetNoStore(); Response.Write(a); Response.End(); } } private bool LogWrite(string filepath) { try { XmlDocument xdoc = new XmlDocument(); //if (!File.Exists(filepath)) //{ xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\">" + "</rss>"); //} //else //{ // xdoc.Load(filepath); //} XmlNode root = xdoc.SelectSingleNode("rss"); XmlElement xe_cha = xdoc.CreateElement("channel"); //header XmlElement xe_Title = xdoc.CreateElement("title"); xe_Title.InnerText = "此rss为会议列表"; XmlElement xe_link = xdoc.CreateElement("link"); xe_link.InnerText = "http://www.baidu.com"; XmlElement xe_description = xdoc.CreateElement("description"); xe_description.InnerText = "列表描述"; xe_cha.AppendChild(xe_Title); xe_cha.AppendChild(xe_link); xe_cha.AppendChild(xe_description); //item for (int i = 0; i < 10; i++) { XmlElement xe_item = xdoc.CreateElement("item"); xe_cha.AppendChild(xe_item); XmlElement item_Title = xdoc.CreateElement("title"); item_Title.InnerText = "会议" + i; XmlElement item_link = xdoc.CreateElement("link"); item_link.InnerText = "http://www.baidu.com?id=" + i; XmlElement item_description = xdoc.CreateElement("description"); item_description.InnerText = "会议描述" + i; xe_item.AppendChild(item_Title); xe_item.AppendChild(item_link); xe_item.AppendChild(item_description); } root.AppendChild(xe_cha); // 保存存储信息的XML文件 xdoc.Save(filepath); xdoc = null; } catch { } return true; } } //根目录创建web文件夹用于存放xml文件 //根目录创建images文件夹存放rss按钮图片,此按钮实现跳转到此页面的功能,此按键在其它的页面中。