首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用System.ServiceModel.Syndication分页RSS

使用System.ServiceModel.Syndication分页RSS
EN

Stack Overflow用户
提问于 2014-04-11 03:18:19
回答 1查看 551关注 0票数 0

我正在尝试使用RSS-feed实现从System.ServiceModel.Syndication中获得的帖子的分页。然而,我不知道如何做到这一点,什么是最好的方法。

到目前为止,我使用一个Listview在代码背后显示由它获取的数据:

代码语言:javascript
复制
// Link to the RSS-feed.
string rssUri = "feed.xml";
var doc = System.Xml.Linq.XDocument.Load(rssUri);

// Using LINQ to loop out all posts containing the information i want.
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")

     select new
     {
          Title = el.Element("title").Value,
          PubDate = el.Element("pubDate").Value,

          Enclosure = el.Element("enclosure").Attribute("url").Value,
          Description = el.Element("description").Value
      };

// Binding the data to my listview, so I can present the data.
lvFeed.DataSource = rssFeed;
lvFeed.DataBind();

那我该从这里去哪?我猜有一种方法是在我的DataPager中使用Listview?然而,我不确定如何使用该控件,是否应该将所有数据发送到某个列表或类似于IEnumerable<>的列表中

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-11 14:13:30

经过一些尝试和错误,并阅读了DataPager,我想出了下面的解决方案,现在工作得很好!

首先,我为我的对象创建了一个类,使用它,我为在页面加载时启动的ListView设置了一个select方法,将数据绑定到它。这里的诀窍是使用ICollection接口,并将数据发送到列表中。这是这个select方法的工作代码,希望它能帮助其他人解决同样的问题!)

代码语言:javascript
复制
ICollection<Podcast> SampleData()
{
    string rssUri = "http://test.test.com/rss";
    var doc = System.Xml.Linq.XDocument.Load(rssUri);

    ICollection<Podcast> p = (from el in doc.Elements("rss").Elements("channel").Elements("item")

                         select new Podcast
                         {
                             Title = el.Element("title").Value,
                             PubDate = el.Element("pubDate").Value,
                             Enclosure = el.Element("enclosure").Attribute("url").Value,
                             Description = el.Element("description").Value
                              }).ToList();
        return p;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23002866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档