RSS自定义对象-ASP.NET RSS开发
Repeater控件,IHttpHandler的方式都没有解决拼接XML代码的问题。而且会发现,写的多了RSS的固定格式的拼接过程就是一个痛苦的过程。所以就定义了RSS的一个数据结构,具体的输出形式由专门的类来复杂。这样开发人员只要提供一个数据格式,就可以输出所需要的RSS.
RssChanel
负责Rss中Chanel信息的结构,如频道说明、频道RSS地址等
RssItem
Rss中Item中的具体信息,也就文章的内容了
RssEnum
具体的RSS输出类型,比如Atom、Rss。通过该枚举告诉RssBuiler需要什么样的输出格式
RssBuilder
负责最终的XML呈现,也就是拼接后的结果了
protected override void OnLoad(EventArgs e)
{
Response.ContentType = "text/xml";
RssChanel chanel = new RssChanel();
chanel.Title = "商户信息";
chanel.Description = "提供商户的信息列表";
foreach (var shop in RssData.GetShops())
{
RssItem item = new RssItem();
item.Title = shop.ShopName + shop.BranchName;
item.Description = shop.Address;
item.Link = "http://www.pumaboyd.com/shop/" + shop.ShopID;
item.Author = shop.AddUser;
item.PubDate = shop.AddTime;
item.Guid = "http://www.pumaboyd.com/shop/" + shop.ShopID;
chanel.Items.Add(item);
}
Response.Write(RssBuilder.Builder(chanel));
}
具体看总的DEMO
[...] RSS自定义对象 [...]