您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何通過XmlTextWriter實現(xiàn)生成RSS聚合頁XML內(nèi)容信息,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
通過XmlTextWriter實現(xiàn)生成RSS聚合頁XML內(nèi)容信息
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頁的實現(xiàn)"); 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(); } }
關(guān)于“如何通過XmlTextWriter實現(xiàn)生成RSS聚合頁XML內(nèi)容信息”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。