JavaScript Editor Free JavaScript Editor     JavaScript Debugger 




Main Page

Previous Page
Next Page

7.5. RSS

Really Simple Syndication, or RSS, is a dialect of XML that is commonly used for providing news-related content. Things such as news headlines are the realm of RSS. The only issue is that because RSS is XML, it doesn't appear as pretty as HTML does in a web browser. Consider the RSS shown in Listing 7-4 as an example.

Listing 7-4. RSS Example

<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>NEWS!</title>
    <link>http://overlord.gov/</link>
    <description>Latest news</description>
    <language>en-us</language>
    <pubDate>Tue, 29 Nov 2005 03:00:00 GMT</pubDate>

    <lastBuildDate>Tue, 29 Nov 2005 03:07:00 GMT</lastBuildDate>
    <docs>http://blogs.overlord.gov/rss</docs>
    <generator>My Generator</generator>
    <managingEditor>Bob@gol.com</managingEditor>
    <webMaster>webmaster@gol.com</webMaster>

    <item>
      <title>Galactic Overlord Resigns</title>
      <link>http://overlord.gov/news/2005/news-resign.aspx</link>
      <description>
       The much despised Galactic Overlord has announced
       his resignation as the Blorf fleet entered
        orbit.
      </description>
     <pubDate>Tue, 29 Nov 2005 03:07:00 GMT</pubDate>
     <guid>http://overlord.gov/news/2005/11/28.html#item1</guid>
    </item>
    <item>
      <title>Earth's Moon Stolen</title>
      <link>http://overlord.gov/news/2005/news-moon.aspx</link>
      <description>
       Luna, the often photographed natural satellite of
       Earth, has been reported stolen. According to a
       UN spokesperson, at this moment, there are no
        suspects.
       </description>
      <pubDate>Tue, 29 Nov 2005 05:28:00 GMT</pubDate>
      <guid>http://overlord.gov/news/2005/11/28.html#item2</guid>
    </item>
  </channel>
</rss>

Not very pretty, is it? There are, however, ways to prettify it. (Wow, who would have thought that prettify was a word? Oops, off the subject matter.) Using JavaScript and the DOM methods and properties, it is possible to extract only the headlines from the RSS shown. For example, the getElementsByTagname or the getNamedItem properties could be used to obtain the title elements. The content of these elements could then be displayed on the page as a hyperlink. Clicking on the link could then fire a JavaScript handler that would display the description element.

The purpose of this side trip into the wonderful world of Really Simple Syndication was to merely show some of the possibilities of XML. When information is available as XML, it can at times be treated as something like a database. In essence, XML is not only the data itself, but also the source of subsets of that data.


Previous Page
Next Page




JavaScript Editor Free JavaScript Editor     JavaScript Debugger


©