如何打造RSS阅读器
如何打造RSS阅读器
电子科技大学软件学院03级02班 周银辉
关键点:下载RSS订阅所对应的XML文件,解析该XML文件
该类XML文件其形如:
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?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/">
 <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>
 <channel>
 <title>博客园-this.Study(DateTime.Now)</title>
  <title>博客园-this.Study(DateTime.Now)</title> 
 <link>http://www.cnblogs.com/zhouyinhui/</link>
  <link>http://www.cnblogs.com/zhouyinhui/</link> 
 <description>专业因为专注</description>
  <description>专业因为专注</description> 
 <language>zh-cn</language>
  <language>zh-cn</language> 
 <lastBuildDate>Mon, 16 Oct 2006 05:33:31 GMT</lastBuildDate>
  <lastBuildDate>Mon, 16 Oct 2006 05:33:31 GMT</lastBuildDate> 
 <pubDate>Mon, 16 Oct 2006 05:33:31 GMT</pubDate>
  <pubDate>Mon, 16 Oct 2006 05:33:31 GMT</pubDate> 
 <ttl>60</ttl>
  <ttl>60</ttl> 
 <item>
 <item>
 <title>真正的代码宝库:Google Code Search</title>
  <title>真正的代码宝库:Google Code Search</title> 
 <link>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</link>
  <link>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</link> 
 <dc:creator>周银辉</dc:creator>
  <dc:creator>周银辉</dc:creator> 
 <author>周银辉</author>
  <author>周银辉</author> 
 <pubDate>Fri, 13 Oct 2006 09:12:00 GMT</pubDate>
  <pubDate>Fri, 13 Oct 2006 09:12:00 GMT</pubDate> 
 <guid>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</guid>
  <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>
  <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>
  <comments>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html#Feedback</comments> 
 <slash:comments>2</slash:comments>
  <slash:comments>2</slash:comments> 
 <wfw:commentRss>http://www.cnblogs.com/zhouyinhui/comments/commentRss/528421.html</wfw:commentRss>
  <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>
  <trackback:ping>http://www.cnblogs.com/zhouyinhui/services/trackbacks/528421.html</trackback:ping> 
 <description>
 <description>
 < ]]>
  ]]> 
 </description>
  </description>
 </item>
 </item>
 </channel>
 </channel>
 </rss>
 </rss>
如何下载
可以简单地利用 System.Net.WebClient 类,其对象有一个OpenRead(string url)方法,该方法可以打开一个Stream,可以使用该Stream来创建一个XmlDocument
 WebClient client = new WebClient();
 WebClient client = new WebClient();
 XmlDocument doc = null;
 XmlDocument doc = null;

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

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

RssChannel RssChannel
RssChannel
 RssFeed
RssFeed
---------------------------------------------------------------------
下载Demo:https://files.cnblogs.com/zhouyinhui/DemoForRss.rar
电子科技大学软件学院03级02班 周银辉
关键点:下载RSS订阅所对应的XML文件,解析该XML文件
该类XML文件其形如:
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?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/">
 <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>
 <channel> <title>博客园-this.Study(DateTime.Now)</title>
  <title>博客园-this.Study(DateTime.Now)</title>  <link>http://www.cnblogs.com/zhouyinhui/</link>
  <link>http://www.cnblogs.com/zhouyinhui/</link>  <description>专业因为专注</description>
  <description>专业因为专注</description>  <language>zh-cn</language>
  <language>zh-cn</language>  <lastBuildDate>Mon, 16 Oct 2006 05:33:31 GMT</lastBuildDate>
  <lastBuildDate>Mon, 16 Oct 2006 05:33:31 GMT</lastBuildDate>  <pubDate>Mon, 16 Oct 2006 05:33:31 GMT</pubDate>
  <pubDate>Mon, 16 Oct 2006 05:33:31 GMT</pubDate>  <ttl>60</ttl>
  <ttl>60</ttl>  <item>
 <item> <title>真正的代码宝库:Google Code Search</title>
  <title>真正的代码宝库:Google Code Search</title>  <link>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</link>
  <link>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</link>  <dc:creator>周银辉</dc:creator>
  <dc:creator>周银辉</dc:creator>  <author>周银辉</author>
  <author>周银辉</author>  <pubDate>Fri, 13 Oct 2006 09:12:00 GMT</pubDate>
  <pubDate>Fri, 13 Oct 2006 09:12:00 GMT</pubDate>  <guid>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html</guid>
  <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>
  <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>
  <comments>http://www.cnblogs.com/zhouyinhui/archive/2006/10/13/528421.html#Feedback</comments>  <slash:comments>2</slash:comments>
  <slash:comments>2</slash:comments>  <wfw:commentRss>http://www.cnblogs.com/zhouyinhui/comments/commentRss/528421.html</wfw:commentRss>
  <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>
  <trackback:ping>http://www.cnblogs.com/zhouyinhui/services/trackbacks/528421.html</trackback:ping>  <description>
 <description> < ]]>
  ]]>  </description>
  </description> </item>
 </item> </channel>
 </channel> </rss>
 </rss>如何下载
可以简单地利用 System.Net.WebClient 类,其对象有一个OpenRead(string url)方法,该方法可以打开一个Stream,可以使用该Stream来创建一个XmlDocument
 WebClient client = new WebClient();
 WebClient client = new WebClient(); XmlDocument doc = null;
 XmlDocument doc = null;
 try
            try {
            { using (Stream stream = client.OpenRead(url))
                using (Stream stream = client.OpenRead(url)) {
                { doc = new XmlDocument();
                    doc = new XmlDocument(); doc.Load(stream);
                    doc.Load(stream); }
                } }
            } catch
            catch {
            { throw;
                throw; }
            }
 if (doc != null)
            if (doc != null) {
            { // do something else
               // do something else }
            }
如何解析下载的XML文件:
注意到这样一个层次关系:一个RSS包含n个RssFeed,一个RssFeed包含n个RssChannel,RssChannel一个包含n个Item。这里的Item即一个项,它通常是一篇文章,包含标题、Url地址、简短描述等等.
RssItem:

RssChannel
 RssChannel
RssChannel
RssFeed
 RssFeed
RssFeed---------------------------------------------------------------------
下载Demo:https://files.cnblogs.com/zhouyinhui/DemoForRss.rar
 
                     
                    
                 
                    
                
 
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号