(*^__^*)这个才是真正的主角。RSS开发了一圈,突然发现MS在.NET3.5下面提供了SyndicationFeed(需要引用System.ServiceModel.Syndication.dll)。实现的思路和RSS自定义对象一样。但毕竟是MS官方的,从对标准格式的支持,到可扩展性上是无可比拟的。所以延用老规矩,和.NET Framework一起工作,慢慢转到使用这个。内置的方法就是已经支持RSS、ATOM的转换。
protected override void OnLoad(EventArgs e)
{
SyndicationFeed feed = new SyndicationFeed("商户信息", "提供商户信息列表", new Uri("http://www.pumaboyd.com/feed"));
Collection<SyndicationItem> items = new Collection<SyndicationItem>();
foreach (var shop in RssData.GetShops())
{
SyndicationItem item = new SyndicationItem();
item.Title = new TextSyndicationContent(shop.ShopName + shop.BranchName);
item.Content = new TextSyndicationContent(shop.Address);
item.Summary = new TextSyndicationContent(shop.Address);
item.Links.Add(new SyndicationLink(new Uri("http://www.pumaboyd.com/shop/" + shop.ShopID)));
item.Authors.Add(new SyndicationPerson("pumaboyd@163.com",shop.AddUser,"http://www.pumaboyd.com"));
item.PublishDate = shop.AddTime;
item.Id = "http://www.pumaboyd.com/shop/" + shop.ShopID;
items.Add(item);
}
feed.Items = items;
Response.ContentType = "application/rss+xml";
var output = new StringWriter();
var writer = new XmlTextWriter(output);
feed.SaveAsRss20(writer);
Response.Write(output.ToString());
}