例子: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 instanceStringReader 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 ListBoxfeedListBox.ItemsSource = feed.Items; //SyndicationItemloadFeedButton.Content = "Refresh Feed";});}
转载于:https://www.cnblogs.com/1314ren/p/3259843.html
例子:RSS Reader Sample相关推荐
- Native Rss Reader 的资料
转:http://hi.baidu.com/mikyliang/blog/item/11d420d3135832013af3cf19.html RSS文档的构成 2007-05-04 14:58 RS ...
- AJAX RSS Reader Step by Step Tutorial
在网上找到一篇关于ajax rss reader的文章,写得很好,而且简单明了,现翻译如下,不当之处,还请见谅(原文地址:http://ajax.phpmagazine.net/2005/11/aja ...
- 好用的RSS阅读器-My RSS Reader
我对好用的RSS阅读器定义是 必须是免费的 必须可以自定义订阅源 必须是简洁的,不要华而不实 必须有夜间模式,毕竟保护眼睛是头等大事 基于以上几点,开发了 My RSS Reader . 目前已经发布 ...
- RSS Reader for MAC Code
RSS Reader for MAC Code 该项目代码来自于王志刚 <软件创富密码:iPhone应用程序开发攻略之深入浅出Objective-C 2.0>一书,这是一个图例很丰富的书, ...
- PhoneGap RSS Reader
这是关于如何使用phoneGap来开发手机上的RSS阅读器的文章,原作者分别写了四个版本.如下所示: 原文链接:http://www.raymondcamden.com/index.cfm/2011/ ...
- Sharepoint 2019 RSS Reader
1.激活网站集功能和网站功能的SharePoint Server 标准版网站集功能 2.貌似开通匿名才能进行RSS订阅 3.在库中开通rss订阅,点击库 即可看到rss 4.添加rss reader ...
- Blog RSS Reader 资料整理
打算在空闲的时候做一个个人使用的Blog RSS Reader,今天开始收集资料 dim objHTTP,objXML,objXSL Set objXSL = Server.CreateObject( ...
- RSS Reader实例开发之系统设计
系统设计 基于OPhone的RSS Reader将以Google Reader的功能为参考,并充分考虑到手机屏幕的限制.RSS Reader将实现以下几个Activity: 1. Ma ...
- RSS Reader实例开发之使用Service组件
原文地址::http://www.ophonesdn.com/article/show/122 到目前为止,我们已经实现了RSS Reader的基本功能,在这个OPhone应用程序中,我们使用Acti ...
最新文章
- 【 C 】用链表实现堆栈
- python 地址模糊匹配_使用python处理selenium中的xpath定位元素的模糊匹配问题
- Halcon知识:如何用mfc显示halcon读入图象
- linux中lvs命令详解,LVS之三:ipvsadm常用管理命令介绍 | 旺旺知识库
- 力扣:7整数反转(python)
- 303.	Range Sum Query - Immutable
- php invalid access,PHP出错消息PHP has encountered an Access Violation at XXXXXXXX 如何解决?...
- 学习笔记=《你不知道的JavaScript(上卷)》第三章:函数作用域和块级作用域...
- exls导入数据库 php_PHP读取excel文件并导入数据库
- SAP License:数据导入时的问题与总结
- oracle误删除数据恢复
- 高级系统架构师培训笔记
- ArcEngine中的ICommand和ITool
- 51驱动AD9850/AD9851—DDS信号发生器
- php怎么设置段落之间的距离,html中P标签段落与CSS段落间距距离调整
- 关闭Win10自动磁盘碎片整理
- Linux_进程控制(创建进程,等待进程,进程终止)
- 有高血压的少碰这五种毒!它们的伤害悄无声息~
- 七彩虹 pci内存控制器 感叹号 蓝屏 DPC_WATCHDOG_VIOLATION
- 使用jenkins去gitlab拉取代码并部署到服务器