ASP.net 生成Rss订阅
using (XmlTextWriter Writer = new XmlTextWriter(HttpContext.Current.Server.MapPath("~/Rss/HotProductList.xml"), System.Text.Encoding.UTF8))
{
Writer.Formatting = Formatting.Indented;
Writer.WriteStartDocument();
Writer.WriteStartElement("rss");
Writer.WriteAttributeString("version", "2.0");
Writer.WriteStartElement("channel");
Writer.WriteElementString("title", "最新产品");
Writer.WriteElementString("link", "http://shop.myweb08.cn/ProductsList.aspx?type=new");
Writer.WriteElementString("description", "最新产品http://shop.myweb08.cn/ProductsList.aspx?type=new");
DataTable dt = Product.GetProduct();//获取产品DataTable
foreach (DataRow row in dt.Rows)
{
Writer.WriteStartElement("item");
Writer.WriteElementString("title", row["ProductName"].ToString());//产品名
Writer.WriteElementString("link", "http://shop.myweb08.cn/prodct/" + row["ProductName"].ToString() + ".html");//产品链接
Writer.WriteElementString("description", row["Description"].ToString());//产品描述
Writer.WriteElementString("author", "http://shop.myweb08.cn/");
Writer.WriteElementString("pubDate", row["AddTime"].ToString());//更新时间
Writer.WriteEndElement();
}
Writer.WriteEndElement();
Writer.WriteEndElement();
Writer.WriteEndDocument();
}
(已)