There are two kinds of things I know, and I wanted to write them before. Anyone who has experience knows it, just to provide something for those who haven’t been in contact with it, you can refer to it.
The first way:
Create the format xml directly on the front page
< br><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RSSAspx.aspx.cs" Inherits="WebApplication1.RSSAspx" %>
and add the end mark–%>
The background code, just get the data binding from the data.
News news = new News();
DataSet ds = news.GetListByClass(5);
re.DataSource = ds;
re.DataBind();
The second method: directly back-end spelling format xml
The front desk only needs to keep the first line
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind= "Rss.aspx.cs" Inherits="WebApplication1.Rss" %>
Background:
namespace WebApplication1{ public partial class Rss: System.Web.UI.Page {string xmlDoc = “rss.cml”; protected void Page_Load(object sender, EventArgs e) {ITemplate te = re.HeaderTemplate; xmlDoc = Server.MapPath(“.”) + xmlDoc; GetRss(); XmlDocument doc = new XmlDocument(); doc.Load(xmlDoc); Response.ContentType = “text/xml”; doc.Save(Response.Output);} public void GetRss() {News news = new News(); DataSet ds = news.GetListByClass(5) ;//Get data XmlTextWriter writer = new XmlTextWriter(xmlDoc, Encoding.UTF8); writer.Formatting = Formatting.Indented;//Set this indentation writer.WriteStartDocument(true);//Write xml declaration writer.WriteComment(” The realization of RSS”); writer.WriteStartElement(“rss”); writer.WriteAttributeString(“version”, “2 .0”); writer.WriteStartElement(“channel”); writer.WriteStartElement(“title”); writer.WriteString(“jiyong的Rss”); writer.WriteEndElement(); writer.WriteStartElement(“link”); writer .WriteString(“http://” + Request.ServerVariables[“SERVER_NAME”]); writer.WriteEndElement(); writer.WriteStartElement(“description”); writer.WriteString(“xxxx”); writer.WriteEndElement(); writer.WriteStartElement(“copyringht”); writer.WriteString(“2005”); writer.WriteEndElement(); writer.WriteStartElement(“language”); writer.WriteString(“zh-CN”); writer.WriteEndElement(); foreach (DataRow row in ds.Tables[0].Rows)//Traverse the data in the table{ //PId, PTypeId, PUserId, PTitle, PUrl, PDes, PClicks, PTime, PUp, PDown string NewId = row[“PId” ].ToString(); string Heading = row[“PTitle”].ToString(); string content = row[“PDes”].ToString(); string IssuDate = row[“PTime”].ToString(); string ClassId = row[“PTypeId”].ToString(); writer.WriteStartElement(“item”); writer.WriteStartElement(“title”); writer.WriteString(Heading); writer.WriteEndE lement();//End writer.WriteStartElement(“link”); writer.WriteString(“http://” + Request.ServerVariables[“SERVER_NAME”] + “/NewsShow?ID=” + NewId); writer.WriteEndElement ();// writer.WriteStartElement(“description”); writer.WriteString(content); writer.WriteEndElement();// writer.WriteStartElement(“PubDate”); writer.WriteString(IssuDate); writer.WriteEndElement() ; writer.WriteStartElement(“category”); writer.WriteString(ClassId); writer.WriteEndElement(); writer.WriteEndElement();} writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); writer. Close();} }}