:ASP.net RSS購読出力SynciationFeed

3140 ワード


ソースアドレス:http://msdn.microsoft.com/zh-cn/library/system.servicemodel.syndication.syndicationfeed(v=VSL.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("[email protected]",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());

}
 
 
 
  • WebClient webClient=new WebClient()
  • /登録webClient読み出し完了イベント
  • webClient.OpenReadCompletted+=delegate(object sender、OpenReadComplette EventAgs e)
  • {
  • }
  • try
  • {
  • }
  • if(e.Error!=null)
  • {
  • }
  • if(オンエル!=null)
  • {
  • }
  • オンErr(e.Errer);
  • リセット;
  • /ネットワークで取得された情報をRSSエンティティクラス
  • に変換する。
  • List<RssItem>rss Items=new List<RssItem>();
  • Stream stream=e.Result;
  • Xml Reader reponse=Xml Reader.Create(stream);
  • SydicationFeed feeds=SynciationFeed.Load;
  • foreach(SynciationItem f in feeds.Items)
  • {
  • }
  • RssItem rss Item=new RssItem(f.Title.Text,f.Summary.Text,f.PublishDate.ToString()、f.Links[0].Uri.Absolution Uri)
  • rss Items.Add(rss Item)、

  • http://hi.baidu.com/wuyunju/blog/item/88e6dbdd445a813c5982dd88.html