|Tech Jobs | Forum|
by Rael Dornfest
A step-by-step guide to building an RSS 1.0 document by hand. (Updated for RSS 1.0 RC1)
(This article assumes a certain familiarity with the basics of XML markup (the "pointies") and perhaps even a little fiddling with RSS itself. The introductory material is brief, focusing on the distinguishing characteristics of the recently proposed RSS 1.0.)
RSS ("RDF Site Summary") is a lightweight multipurpose extensible metadata description and syndication format. Whew, that was a mouthful! Let's take that bit by bit, shall we.
That's about all I'll say about the overall picture of RSS. I do realize that this was a rather brief overview, but since our intention is to actually create an RSS document, I'll leave further introduction to the many wonderful RSS articles already in existence; visit the Resources section below for a list.
RSS Document Structure
A basic RSS document (or "channel") is structurally rather simple:
Let's start at the top and work our way down, shall we. And since the proposed RSS 1.0 builds on the foundation of RSS 0.9, we'll start by building a 0.9 document and then cover the few basic mechanical changes necessary to bring it into compliance; if you're already familiar with RSS 0.9, feel free to breeze through the first part of the tutorial.
Since we want to focus on the markup, let's keep our example as simple as pie. Mmmm ... pie. Our online pie shoppe, pie-r-squared.com, features a continuously changing lineup of delicious pies for download (alright, online ordering). We'll create an RSS feed to syndicate the choices du jour.
XML Declaration: <?xml version="1.0"?>
While XML documents are not required to begin with an XML declaration, it is generally good practice to do so. The declaration says "This is an XML document" and specifies the version thereof -- the current version of XML itself is 1.0.
Now the XML declaration does also afford you the opportunity to specify your preferred encoding type -- the way you'll be dealing with special characters. Unless specified otherwise, RSS 1.0 assumes UTF-8; let's go ahead and add it for pedantic/illustrative purposes. So the first line of our document (make sure it's the first line!) looks a lot like this:
(By the way, I'll be calling out changes in our evolving document as we go along by highlighting new bits in orange.)
The Container: <rdf:RDF>
Every XML structure can have one and only one outer container -- the "root element." RSS 1.0's root element is borrowed from the earlier 0.9 version. The root element also affords us the opportunity to declare the namespaces we'll be using in our document.
Let's take a pit stop and see what we mean by namespaces.
In my sphere, there exist two Tims, two Jons, and a number of Daves (or variations thereof). To avoid confusion (never mind embarrassment), I have to be sure to clarify which Tim or Jon or Dave I'm referring to. Thank goodness they all have different last names, making Tim O'Reilly distinct from Tim Berners-Lee.
Now, since XML elements and attributes don't have last names, it can be difficult to differentiate between
Now these namespace prefixes (the bit before the colon) are not particularly useful if you don't have a decent definition for what
This scheme effectively identifies the former as "title as defined by the HTML 4.0 specification" and the latter as "title as in O'Reilly book." URLs are used because they're a convenient way for everyone to invent unique names under their own control. The URLs don't have to point to anything useful, but it's nice if they do (documentation, for instance).
Now, since I work for O'Reilly & Associates, a book company, it's fair to assume that when I say the word "title" in the office I'm referring to a book title. I would always qualify when talking about an HTML document title by saying, well, "Web page title" or the like. So my "default namespace," then, in the book world, is declared in XML like so:
You'll notice a lack of prefix associated with the
Mind you, the namespace doesn't refer to the "title" itself, but to the vocabulary which defines it. This rather simplistic example should hopefully provide enough on namespaces to get you going; for more information, be sure to visit the Namespaces in XML W3C recommendation and Tim Bray's "XML Namespaces by Example."
We'll add the default namespace for RSS 0.9 and one for RDF itself to our
Welcome to the channel element, a place to describe a few aspects of our RSS channel. We're required to fill in a title, link, and description. How about:
The channel is titled "Pie-R-Squared" and suggests to the end-user that they render the title as a link to our (imaginary) home page.
Copyright © 2000-2006 OReilly Media, Inc. All Rights Reserved.
All trademarks and registered trademarks appearing on the O'Reilly Network are the property of their respective owners.
For problems or assistance with this site, email