转载:ASP.net RSS 订阅输出 SyndicationFeed

 

源地址:http://msdn.microsoft.com/zh-cn/library/system.servicemodel.syndication.syndicationfeed(v=VS.95).aspx

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());

}
 
 读入 :
 
 
  1. WebClient webClient = new WebClient();
  2. //注册webClient读取完成事件
  3. webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
  4. {
  5. try
  6. {
  7. if (e.Error != null)
  8. {
  9. if (onError != null)
  10. {
  11. onError(e.Error);
  12. }
  13. return;
  14. }
  15. //将网络获取的信息转化成RSS实体类
  16. List<RssItem> rssItems = new List<RssItem>();
  17. Stream stream = e.Result;
  18. XmlReader response = XmlReader.Create(stream);
  19. SyndicationFeed feeds = SyndicationFeed.Load(response);
  20. foreach (SyndicationItem f in feeds.Items)
  21. {
  22. RssItem rssItem = new RssItem(f.Title.Text, f.Summary.Text, f.PublishDate.ToString(), f.Links[0].Uri.AbsoluteUri);
  23. rssItems.Add(rssItem);
  24. }
源地址:http://hi.baidu.com/wuyunju/blog/item/88e6dbdd445a813c5982dd88.html
原文地址:https://www.cnblogs.com/finehappy/p/2200462.html