Online Book Reader

Home Category

AJAX In Action [248]

By Root 4022 0
to the RSS specifications, but both are allowed in an item element. There are also eight other optional elements that can be added to the item. Returning to the newspaper analogy, an article normally contains the story, the author, the source, and a title. In the same way, each item element in an RSS feed can have separate titles, authors, sources, and so on. All of the optional elements that are available for the item element are shown in table 13.3.

Table 13.3 Item elements

Element

Description

Example

author

The item author’s

Pascarello@javaranch.com

email address

category

Includes the item in

Programming

one or more categories

comments

The URL of the page

http://radio.javaranch.com/pascarello/2005/05/25/

for comments that

1117043999998.html#comments

relates to this item

continued on next page

Licensed to jonathan zheng

Creating the rich user interface

509

Table 13.3 Item elements (continued)

Element

Description

Example

description

The item summary

Ajax allows developers to improve the UI by making a web

application act like a client application.

enclosure

Describes the media

attached to the item

length="5908124" type="audio/mpeg"/>

guid

A string that is a

http://radio.javaranch.com/pascarello/2005/05/25/

unique identifier

1117043999998.html

link

The URL of the item

http://radio.javaranch.com/pascarello/

pubDate

The date the item was

Wed, 25 May 2005 17:59:59 GMT

published

source

The RSS channel the

Eric's Blog

title

The title of the eleAjax Improves UI Development

ment

The heart and soul of the RSS feed are the title and the description. The title gives us a small insight into what the article is, whereas the description element can be one of two things: a synopsis about the article or the entire article itself. There is no set standard on how the description element is used. To determine how to handle it, we have to look at the individual feeds before we start to write the RSS feed reader. If it’s a synopsis, we can compare it to a blurb on the front of a magazine where it says, “see page 10 for more information.” That is where the link element comes into use. The link is the URL to the entire article on the author’s site. Most RSS feeds try to utilize as many of the optional elements as possible in order to provide developers, like us, the tools to make our RSS reader as robust as possible. With better data at our hands, we can better display the RSS feed content. For more information about the RSS specification, visit http://backend.userland.com/rss. Now that we understand the basic elements of the RSS document, we can create our Ajax-based RSS reader. 13.2 Creating the rich user interface

In this chapter, we create an RSS feed viewer that obtains the XML feeds from websites without using a server-side language or a client application RSS reader. Licensed to jonathan zheng

510

CHAPTER 13

Building stand-alone applications with Ajax

Ajax allows us to view the information with a web page that is stored on our desktop. This example demonstrates that Ajax does not have to run with a web server that has a server-side language such as .NET or JSP. As long as we have an active Internet connection, we are able to access RSS feeds from any site we desire. (If you are running a Mozilla browser, see section 13.6.1. You must overcome Mozilla’s security restrictions, which we discussed in chapter 7, before you try to execute the code in this project.)

13.2.1 The process

If you find yourself scanning multiple websites for content every day, you will be able to avoid that by running this reader. The viewer will be able to show multiple feeds on one page.

The unique feature of this application is that we are not using any server-side code; we are only obtaining RSS XML documents that are created by the other websites. The complete application

Return Main Page Previous Page Next Page

®Online Book Reader