阅读多个 RSS 源
我目前正在尝试在 Windows Phone 7 上创建一个小型 RSS 阅读器应用程序。
到目前为止,我能够在不同的全景图上显示单个提要,并且运行良好。
然而,在我的主页上,我想显示来自多个 RSS 源的最新新闻。
例如,我在不同的页面上有 feed1、feed2,并且我想在我的主页上显示来自 feed1 和 feed2(或更多)的最新新闻的标题。
这是我用于单个提要
Mainpage_Loaded 的代码:
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("feed-goes-here"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
然后:
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null) return;
XElement xmlItems = XElement.Parse(e.Result);
listBox1.ItemsSource = from x in xmlItems.Descendants("item")
where x.Element("enclosure") != null && x.Element("description") != null
select new RSSitem
{
Description = x.Element("description").Value.Substring(0,100)+"...",
Title = x.Element("title").Value,
ImageSource = x.Element("enclosure").FirstAttribute.Value
};
}
我已经测试了很多方法来解决我的问题,但仍然找不到答案。
所以我的问题是:如何在列表框中显示同一页面上 2 个不同源的最新新闻? 感谢您的帮助和您的时间。
I'm currently trying to create a little RSS reader application on Windows Phone 7.
So far I'm able to display single feeds on different Panoramas and it works fine.
However on my MainPage I want to display the most recent news coming from multiple RSS feeds.
For example I have feed1, feed2 on different pages, and I'd like to show the title of the most recent news coming from both feed1 and feed2 (or more) on my homepage.
Here is the code I've been using for my single feeds
Mainpage_Loaded:
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("feed-goes-here"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
And then :
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null) return;
XElement xmlItems = XElement.Parse(e.Result);
listBox1.ItemsSource = from x in xmlItems.Descendants("item")
where x.Element("enclosure") != null && x.Element("description") != null
select new RSSitem
{
Description = x.Element("description").Value.Substring(0,100)+"...",
Title = x.Element("title").Value,
ImageSource = x.Element("enclosure").FirstAttribute.Value
};
}
I've been testing a lot of methods to solve my problem but still couldn't find the answer.
So my question is : How do i display on a listbox, the most recent news from 2 different feeds on the same page ?
Thank you for your help and for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我建议向 RSSItem 添加 Date 属性:
这样,当您下载两个 RSS 提要时,您可以将它们编织在一起并按日期排序:
用法:
First, I would recommend adding a Date property to RSSItem:
This way, when you download your two RSS feeds, you can weave them together and sort by date:
Usage: