您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何通過XmlTextWriter實現生成RSS聚合頁XML內容信息,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
通過XmlTextWriter實現生成RSS聚合頁XML內容信息
public partial class Rss2 : System.Web.UI.Page { string xmlDoc = "rss.xml"; protected void Page_Load(object sender, EventArgs e) { xmlDoc = Server.MapPath(xmlDoc); GetRSS(); XmlDocument doc = new XmlDocument(); doc.Load(xmlDoc); Response.ContentType = "text/xml"; doc.Save(Response.Output); } /// <summary> /// 取得聚合文章 /// </summary> /// <returns></returns> public void GetRSS() { DataSet ds = new DataSet(); XmlTextWriter writer = new XmlTextWriter(xmlDoc, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(true); writer.WriteComment("RSS頁的實現"); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteStartElement("channel"); writer.WriteStartElement("title"); writer.WriteString("Danny_RSSDemo"); writer.WriteEndElement(); writer.WriteStartElement("link"); writer.WriteString("http://" + Request.ServerVariables["SERVER_NAME"]); writer.WriteEndElement(); writer.WriteStartElement("description"); writer.WriteString("天道酬勤"); writer.WriteEndElement(); writer.WriteStartElement("copyright"); writer.WriteString("Copyright 2005"); writer.WriteEndElement(); writer.WriteStartElement("language"); writer.WriteString("zh-cn"); writer.WriteEndElement(); foreach (DataRow row in ds.Tables[0].Rows) { string NewsId = row["NewsId"].ToString(); string Heading = row["Heading"].ToString(); string Content = row["Content"].ToString(); string IssueDate = row["IssueDate"].ToString(); string ClassId = row["ClassId"].ToString(); writer.WriteStartElement("item"); writer.WriteStartElement("title"); writer.WriteString(Heading); writer.WriteEndElement(); writer.WriteStartElement("link"); writer.WriteString("http://" + Request.ServerVariables["SERVER_NAME"] + "/NewsShow.aspx?ID=" + NewsId); writer.WriteEndElement(); writer.WriteStartElement("description"); writer.WriteCData(Content); writer.WriteEndElement(); writer.WriteStartElement("pubDate"); writer.WriteString(IssueDate); writer.WriteEndElement(); writer.WriteStartElement("category"); writer.WriteString(ClassId); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); writer.Close(); } }
關于“如何通過XmlTextWriter實現生成RSS聚合頁XML內容信息”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。