• 如何打造RSS阅读器


    如何打造RSS阅读器

                                 电子科技大学软件学院03级02班 周银辉

    关键点:下载RSS订阅所对应的XML文件,解析该XML文件

    该类XML文件其形如:
    <?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
     
    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
     
    <channel>
      
    <title>博客园-this.Study(DateTime.Now)</title> 
      
    <link>http://www.cnblogs.com/zhouyinhui/</link> 
      
    <description>专业因为专注</description> 
      
    <language>zh-cn</language> 
      
    <lastBuildDate>Mon, 16 Oct 2006 05:33:31 GMT</lastBuildDate> 
      
    <pubDate>Mon, 16 Oct 2006 05:33:31 GMT</pubDate> 
      
    <ttl>60</ttl> 
     
    <item>
      
    <title>真正的代码宝库:Google Code Search</title> 
      
    <link>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</link> 
      
    <dc:creator>周银辉</dc:creator> 
      
    <author>周银辉</author> 
      
    <pubDate>Fri, 13 Oct 2006 09:12:00 GMT</pubDate> 
      
    <guid>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</guid> 
      
    <wfw:comment>http://www.cnblogs.com/zhouyinhui/comments/528421.html</wfw:comment> 
      
    <comments>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html#Feedback</comments> 
      
    <slash:comments>2</slash:comments> 
      
    <wfw:commentRss>http://www.cnblogs.com/zhouyinhui/comments/commentRss/528421.html</wfw:commentRss> 
      
    <trackback:ping>http://www.cnblogs.com/zhouyinhui/services/trackbacks/528421.html</trackback:ping> 
     
    <description>
      
    <![CDATA[ Google推出代码搜索&nbsp;,可以搜索到无数的开源代码,有让人欣喜若狂的感觉啊.<BR><BR>不用多说,快去看看 <A href="http://www.google.com/codesearch">http://www.google.com/codesearch</A><img src ="http://www.cnblogs.com/zhouyinhui/aggbug/528421.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://zhouyinhui.cnblogs.com/" target="_blank">周银辉</a> 2006-10-13 17:12 <a href="/zhouyinhui/archive/2006/10/13/528421.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>
      
    ]]> 
      
    </description>
     
    </item>
     
    </channel>
     
    </rss>


    如何下载

    可以简单地利用 System.Net.WebClient 类,其对象有一个OpenRead(string url)方法,该方法可以打开一个Stream,可以使用该Stream来创建一个XmlDocument
     WebClient client = new WebClient();
     XmlDocument doc 
    = null;

                
    try
                
    {
                    
    using (Stream stream = client.OpenRead(url))
                    
    {
                        doc 
    = new XmlDocument();
                        doc.Load(stream);
                    }

                }

                
    catch
                
    {
                    
    throw;
                }


                
    if (doc != null)
                
    {
                   
    // do something else
                }


    如何解析下载的XML文件:

    注意到这样一个层次关系:一个RSS包含n个RssFeed,一个RssFeed包含n个RssChannel,RssChannel一个包含n个Item。这里的Item即一个项,它通常是一篇文章,包含标题、Url地址、简短描述等等.

    RssItem:


    RssChannel
    RssChannel

    RssFeed

    RssFeed


    ---------------------------------------------------------------------

    下载Demohttps://files.cnblogs.com/zhouyinhui/DemoForRss.rar
  • 相关阅读:
    Sql Server 创建表(可重复执行--范本)
    Sql Server 存储过程(可重复执行--范本)
    table设置了colspan之后出现td宽度显示不正常
    textarea 自适应高度
    获取系统文件
    牛客网前端编程:计算给定数组 arr 中所有元素的总和
    牛客网前端编程:删除数组中特定元素
    牛客网前端编程:找出元素 item 在给定数组 arr 中的位置
    element+vue:将Unix时间戳转化标准格式
    vue-router使用
  • 原文地址:https://www.cnblogs.com/zhouyinhui/p/530254.html
Copyright © 2020-2023  润新知