bsp; strCode.Append("<description><![CDATA["+description+"]]></description>");
strCode.Append("<PubDate>"+pubdate+"</PubDate>");
strCode.Append("<category>"+ClassId+"</category>");
strCode.Append("</item>");
}
strCode.Append("</channel>");
strCode.Append("</rss>");
return strCode.ToString();
}
(3) XmlTextWriter实现方式2;Rss.aspx.cs
string xmlDoc="rss.xml";
private void Page_Load(object sender, System.EventArgs e)
{
xmlDoc=Server.MapPath(".")+xmlDoc;
GetRSS2();
XmlDocument doc= new XmlDocument();
doc.Load(xmlDoc);
Response.ContentType = "text/xml";
doc.Save(Response.Output);
}
/// <summary>
/// 取得聚合文章
/// </summary>
/// <returns></returns>
public void GetRSS2()
{
News t=new News();
DataSet ds=t.GetListByClass(1);
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("李天平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();
|