Hack 83 Create an RSS 2.0 Document

   

figs/beginner.gif figs/hack83.gif

Create an RSS 2.0 document from a template.

RSS 2.0 is an update of RSS 0.91, and so does not follow the RDF approach taken by RSS 1.0. After RSS 0.91 and RSS 1.0, it is the third most popular RSS format. You can find the spec for RSS 2.0 at http://blogs.law.harvard.edu/tech/rss. It is similar to RSS 0.91, but offers some clarifications and additional elements.

The following, news.xml, is a minimal example of RSS 2.0:

<rss version="2.0">  <channel>   <title>Wy'east Communications</title>   <link>http://www.wyeast.net</link>   <description> Wy'east Communications is an XML consultancy.</description>   <item>    <title>Legend of Wy'east</title>    <link>http://www.wyeast.net/wyeast.html</link>    <description>The Native American story behind the name Wy'east.</description>   </item>  </channel> </rss>

Like RSS 0.91, RSS 2.0 doesn't declare a namespace for its own elements. Also like 0.91, rss is the document element. It must have a version attribute with a value of 2.0.

The channel element is required, as are its children title, link, and description. The language element is required as a child of channel by 0.91, but under 2.0 it is optional. The image element is also required by 0.91; it's optional under 2.0. Table 6-2 compares the required and optional elements of channel in 2.0 and 0.91. The purpose of each is briefly described.

Table 6-2. Child elements of channel in RSS 2.0 and RSS 0.91

Element

Purpose

RSS 2.0

RSS 0.91

title

Title of channel

Required

Required

link

Link to channel

Required

Required

description

Description of channel

Required

Required

language

Language code for channel

Optional

Required

image

Image that represents the channel (required children url, title, and link; optional children description, width, and height)

Optional

Required

copyright

Copyright notice for the channel

Optional

Optional

managingEditor

Email address of managing editor

Optional

Optional

webMaster

Email address of webmaster

Optional

Optional

pubDate

Publication date of channel in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST; though not specified in RFC 822, a four-digit year is allowed (see http://www.ietf.org/rfc/rfc822.txt)

Optional

Optional

lastBuildDate

Last time channel content changed in RFC 822 format, Sat, 01 Jan 05 00:00:27 PST; though not specified in RFC 822, a four-digit year is allowed (see http://www.ietf.org/rfc/rfc822.txt)

Optional

Optional

rating

Platform for Internet Content Selection (PICS) rating (http://www.w3.org/PICS/)

Optional

Optional

docs

Documentation for the RSS format used by channel

Optional

Optional

textInput

A text input box for the channel, such as a search box (required children include title, description, name, and link)

Optional

Optional

skipDays

Days to skip reading channel

Optional

Optional

skipHours

Hours to skip reading channel

Optional

Optional

category

One or more channel categories

Optional

N/A

generator

Name of generator program

Optional

N/A

cloud

Specifies a protocol for publishing and subscribing to feeds

Optional

N/A

ttl

Time to live in minutes

Optional

N/A


Under the item element in RSS 2.0, a description element can contain entity-encoded HTML. In other words, it can hold an article or story in itself, written in HTML (with &amp; for & and &lt; for <). Table 6-3 compares the 0.91 and 2.0 children of item.

Table 6-3. Child elements of item in RSS 2.0 and RSS 0.91

Element

Purpose

RSS 2.0

RSS 0.91

title

Title of item

Optional /Required

Required

link

Link to item

Optional /Required

Required

description

Description of item

Optional /Required

Optional

author

Email address of author of item

Optional

N/A

category

One or more item categories (optional attribute domain)

Optional

N/A

comments

URL for comment page for item

Optional

N/A

enclosure

Describes an object attached to item (required attributes url, length, and type)

Optional

N/A

guid

Globally unique identifier

Optional

N/A

pubDate

Publication date in RFC 822 format

Optional

N/A

source

RSS channel the item came from (required attribute url)

Optional

N/A


An item element may represent a story such as an article from a newspaper or a magazine. In such a case, the item's description child should contain a synopsis of the story, with a URI in the link element pointing to the full story. On the other hand, an item may also contain a complete story. In this case, the description child of item will contain the text of the whole story (which may be entity-encoded HTML), so the link and title children of item don't have to be included. Though all elements of item are optional in 2.0, at least one title or description must be present.

RSS 2.0 restricts the first non-whitespace characters in the content of link and url elements. This content must begin with a URI scheme registered at IANA (http://www.iana.org/assignments/uri-schemes), such as ftp://, http://, https://, mailto:, or news://. RSS 0.91 allows only http:// and ftp://.


6.5.1 See Also

  • With Radio UserLand, you can generate an RSS 2.0 document for your Radio weblog by going to Prefs and then clicking RSS Configuration under Weblogs. A link to this RSS document will appear on your weblog home page.



XML Hacks
XML Hacks: 100 Industrial-Strength Tips and Tools
ISBN: 0596007116
EAN: 2147483647
Year: 2006
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net