例子:RSS Reader Sample
本例演示了Rss xml信息的获取,以及如何使用SyndicationFeed来进行符合Rss规范的xml进行解析。
SyndicationFeed 解析完成后 可以得到SyndicationItem数组,她具有以下属性:
名称 | 说明 | |
---|---|---|
![]() |
AttributeExtensions | 获取联合项的属性扩展。 |
![]() |
Authors | 获取联合项的作者。 |
![]() |
BaseUri | 获取和设置 SyndicationItem 实例的基统一资源标识符 (URI)。 |
![]() |
Categories | 获取联合项的联合类别。 |
![]() |
Content | 获取和设置联合项的内容。 |
![]() |
Contributors | 获取联合项的参与者。 |
![]() |
Copyright | 获取和设置联合项的版权信息。 |
![]() |
ElementExtensions | 获取联合项中包含的元素扩展。 |
![]() |
Id | 获取和设置联合项的 ID。 |
![]() |
LastUpdatedTime | 获取和设置联合项的上次更新时间。 |
![]() |
Links | 获取联合项中包含的链接。 |
![]() |
PublishDate | 获取和设置联合项的发布日期。 |
![]() |
SourceFeed | 获取和设置联合项的源。 |
![]() |
Summary | 获取和设置联合项的摘要。 |
![]() |
Title | 获取和设置联合项的标题。 |
代码实现:
1. UI中绑定SyndicationFeed相关属性
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top">
<TextBlock TextDecorations="Underline" FontSize="24" Name="feedTitle" TextWrapping="Wrap" Margin="12,0,0,0" HorizontalAlignment="Left" Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" />
<TextBlock Name="feedSummary" TextWrapping="Wrap" Margin="12,0,0,0" Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmer}}" />
<TextBlock Name="feedPubDate" Foreground="{StaticResource PhoneSubtleBrush}" Margin="12,0,0,10" Text="{Binding PublishDate.DateTime}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
2. 建立网络连接,获取XML数据
// WebClient is used instead of HttpWebRequest in this code sample because
// the implementation is simpler and easier to use, and we do not need to use
// advanced functionality that HttpWebRequest provides, such as the ability to send headers.
WebClient webClient = new WebClient(); // Subscribe to the DownloadStringCompleted event prior to downloading the RSS feed.
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted); // Download the RSS feed. DownloadStringAsync was used instead of OpenStreamAsync because we do not need
// to leave a stream open, and we will not need to worry about closing the channel.
webClient.DownloadStringAsync(new System.Uri("http://n.rss.qq.com/rss/tech_rss.php"));
3. 解析XML,并更新UI
// This method sets up the feed and binds it to our ListBox.
private void UpdateFeedList(string feedXML)
{
// Load the feed into a SyndicationFeed instance
StringReader stringReader = new StringReader(feedXML);
XmlReader xmlReader = XmlReader.Create(stringReader);
SyndicationFeed feed = SyndicationFeed.Load(xmlReader); // In Windows Phone OS 7.1, WebClient events are raised on the same type of thread they were called upon.
// For example, if WebClient was run on a background thread, the event would be raised on the background thread.
// While WebClient can raise an event on the UI thread if called from the UI thread, a best practice is to always
// use the Dispatcher to update the UI. This keeps the UI thread free from heavy processing.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
// Bind the list of SyndicationItems to our ListBox
feedListBox.ItemsSource = feed.Items; //SyndicationItem
loadFeedButton.Content = "Refresh Feed";
}); }
例子:RSS Reader Sample的更多相关文章
- Tiny Rss Reader - 迷你RSS阅读器
发布新软件 TinyRss: Windows平台上的一个小巧的Rss阅读器. 用户界面: 项目地址: https://github.com/movsb/tinyrss.git 测试下载: http:/ ...
- 新RSS reader
阅读之前采取正确的方法,但是非常不介意,没有收到订阅很大. 走到今天 http://www.feedspot.com 2014/11/8追加:用下来感觉不错. feedspot 的相关快捷键例如以下: ...
- RSS Reader in PC & iPhone
PC上当然是用feedly web版.但出乎意料的是,iPhone上最好用的居然是safari版QQ邮箱...
- sencha touch的开源插件和例子
写了好久的sencha touch,没想到换工作竟然一年多没有搞了.因为项目的缘故收集了好多的组件,由于懒惰,没有整理,现在想想有点后悔了,再加上如果就这样丢弃,感觉有些遗憾,今天整理了一下放在git ...
- C#版简易RSS阅读器
C#版简易RSS阅读器.由VB版修改完成,感谢aowind的技术支持! 源代码: using System; using System.Drawing; using System.Collection ...
- iphone Dev 开发实例8: Parsing an RSS Feed Using NSXMLParser
From : http://useyourloaf.com/blog/2010/10/16/parsing-an-rss-feed-using-nsxmlparser.html Structure o ...
- 关于RSS
RSS(简易信息聚合)是一种消息来源格式规范,用以聚合经常发布更新数据的网站,例如博客文章.新闻.音频或视频的网摘.RSS文件(或称做摘要.网络摘要.或频更新,提供到频道)包含了全文或是节录的文字,再 ...
- .Net开发者必知的技术类RSS订阅指南
目录 RSS订阅资源 .Net基金会 MSDN中文版 杂志 微软 Github 系列 微软DevBlog系列 InfoQ中文版系列 如何找到大佬的 Twitter/Youtube/Stackoverf ...
- 如何用RSS订阅?
本文由云+社区发表 摘要:我们常常会有订阅别人文章的需求,有更新的时候希望能有提醒的功能,RSS就是这样一个订阅的方式.很多网站上看到RSS的入口,点进去以后总是显示一堆的XML代码,我们来看看怎么使 ...
随机推荐
- 界面布局之表格布局TableLayout+TableRow
一.基础知识: TableLayout置底,TableRow在TableLayout的上面,而Button.TextView等控件就在TableRow之上, 另外,TableLayout之上也可以单独 ...
- Sublime Text3 快捷键
选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数 ...
- Qt编程'""hello world
#include<QApplication>#include<QLabel>int main(int argc,char*argv[]){QApplicatin app(arg ...
- File API 读取上传的文件
1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...
- CentOS6.5 根目录结构划分
/bin 系统的执行程序文件/dev 硬件设备的文件目录/home 用户的家目录/lib 系统库文件目录/mnt 挂载目录,外设的挂载/media 经常用于媒体文件 ...
- indexOf 用法
一.字符串的IndexOf()方法: (括号里的为子字符串) 搜索在该字符串上是否出现了作为参数传递的子字符串,如果找到子字符串,则返回子字符串在该字符串上出现的起始位置 (0表示第一个字符,1表示第 ...
- Ubuntu16.04安装Samba
在新装的ubuntu16.04下安装samba. 安装好samba后备份下配置文件: zhuben@zb:~$ sudo apt-get install samba zhuben@zb:~$ cd / ...
- forever让nodejs应用后台执行
nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让nodejs应用当成服务,在后台执行呢? 最简单的办法: $ nohup node app.js & ...
- wmic 命令的一个汇总,功能很强大
获得系统版本信息wmic datafile where Name='c:\\windows\\explorer.exe' get Manufacturer,Version,Filename 获得系统进 ...
- 在windows不能正常使用boost og
现象: 1. 在两个不同的dll中使用static的boost.log.在一个dll中的设置在另一个dll中没有起作用 原因:core::get()返回的是一个单例.在不同的dll中是不同的对象 解决 ...