zoukankan      html  css  js  c++  java
  • 转载: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
  • 相关阅读:
    String,StringBuffer,StringBuilder简单对比
    Java基本数据类型
    EasyMock框架的使用详解
    Python3.6在win7中无法正常运行的问题
    zabbix3.4源码安装步骤
    hadoop_2.6.5集群安装
    Cassandra2.2.10安装过程
    JDK1.8安装
    zookeeper3.4.6安装
    python3.6的安装及cx_oracle安装
  • 原文地址:https://www.cnblogs.com/finehappy/p/2200462.html
Copyright © 2011-2022 走看看