11/06/2011

RSS 2.0 結構

最近要寫個Android reader,來訂閱自己感興趣的新聞,首先要了解RSS的結構,不過RSS有很多版本,下列針對RSS 2.0結構來說明~
XML:
2. <!-- XML​​版本和字符集 -->
3. <?xml version="1.0"?>
4. <!-- RSS版本 -->
5. <rss version="2.0">


6. <!-- 以下為頻道信息及新聞列表-->
7. <channel>
8. <!-- 頻道總體信息:開始 -->
9. <!-- 頻道標題 -->
10. <title>Lift Off News</title>
11. <!-- 頻道鏈接的總地址 -->
12. <link>http://liftoff.msfc.nasa.gov/</link>
13. <!-- 頻道描述文字 -->
14. <description>Liftoff to Space Exploration.</description>
15. <!-- 頻道使用的語言(zh-cn表示簡體中文) -->
16. <language>en-us</language>
17. <!-- 頻道發布的時間 -->
18. <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
19. <!-- 頻道最後更新的時間-->
20. <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
21. <docs>http://blogs.law.harvard.edu/tech/rss</docs>
22. <!-- 頻道生成器 -->
23. <generator>Weblog Editor 2.0</generator>
24. <managingEditor>editor@example.com</managingEditor>
25. <webMaster>webmaster@example.com</webMaster>
26. <ttl>5​​</ttl>
27. <!-- 頻道總體信息:結束 -->
28. <!-- 每條RSS新聞信息都包含在item節點中, -->
29. <item>
30. <!-- 新聞標題 -->
31. <title>Star City</title>
32. <!-- 新聞鏈接地址 -->
33. <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
34. <!-- 新聞內容簡要描述 -->
35. <description>How do Americans get ready to work with Russians aboard the
36. International Space Station? They take a crash course in culture, language
37. and protocol at Russia's Star City.</description>
38. <!-- 新聞發佈時間 -->
39. <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
40. <!-- 新聞目錄 -->
41. <category>IT</category>
42. <!-- 新聞作者 -->
43. <author>bill</author>
44. <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>
45. </item>
46.​​ <item>
47. <title>Space Exploration</title>
48. <link>http://liftoff.msfc.nasa.gov/</link>
49. <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada
50. will experience a partial eclipse of the Sun on Saturday, May 31st.</description>
51. Fri, 30 May 2003 11:06:42 GMT</pubDate>
52. <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid>
53. </item>
54. <item>
55. <title>The Engine That Does More</title>
56. <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link>
57. <description>Before man travels to Mars, NASA hopes to design new engines
58. that will let us fly through the Solar System more quickly. The proposed
59. VASIMR engine would do that.</description>
60. Tue, 27 May 2003 08:37:32 GMT</pubDate>
61. <guid>http://www.zhanghangfeng.cn/rss.xml</guid>
62. </item>
63. <item>
64. <title>Astronauts' Dirty Laundry</title>
65. <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link>
66. <description>Compared to earlier spacecraft, the International Space
67. Station has many luxuries, but laundry facilities are not one of them.
68. Instead, astronauts have other options.</description>
69. Tue, 20 May 2003 08:56:02 GMT</pubDate>
70. <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid>
71. </item>
72. </channel>
73. </rss>

由上可知,主要是獲得item下的title、link、pubDate、description的內容,rss閱讀器最核心的是解析rss文件,其實就是解析xml文件

沒有留言:

張貼留言

請留言~一起討論吧~