Let's begin by taking a look at an RSS 2.0 document. To create your own RSS document, you need to know the names of the various parts of such a document. Start composing your RSS document by opening an RSS creator program such as NewzAlert Composer and giving your RSS feed a name"Steve's News" in the example shown here (Figure 3.1). This is the RSS feed name that appears in the RSS reader (Figure 3.2). Figure 3.1. NewzAlert Composer provides property information about your feed.Figure 3.2. Here's the NewzAlert feed displayed in RSSReader.The name of the actual RSS document is news.xml, and like all XML documents, this one starts with an XML declaration: <?xml version="1.0" encoding="ISO-8859-1"?> . . . The next line of code in the RSS document is called the document element because it contains all other elements in the document. Thus, it is here that the document specifies that its version is RSS 2.0. <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> . . . </rss> As you can see, the <rss> element looks much like the HTML elements you're already familiar with. (For more about how XML elements work, see Chapter 4.) Inside the <rss> element is a <channel> element. A channel element, referred to as the channel in an RSS document, provides details about the feed you're creating. <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> . . . </channel> </rss> You'll see many different elements inside an RSS <channel> element. When you're creating your own RSS feeds using a tool like NewzAlert Composer, these are the elements you need to know about:
Here's what these elements for our news.xml code look like as stored by NewzAlert Composer: <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <generator>NewzAlert Composer v1.70.6, Copyright (c) 2004-2005 Castle Software Ltd, http://www.NewzAlert.com</generator> <lastBuildDate>Thu, 08 Dec 2005 14:01:27 -0500</lastBuildDate> <pubDate>Thu, 08 Dec 2005 14:01:34 -0500</pubDate> <title>Steve's News</title> <description><![CDATA[This feed contains news from Steve!]]></description> <link>http://www.rssmaniac.com/steve</link> <language>en-us</language> <copyright>(c) 2006</copyright> <managingEditor>Steve</managingEditor> <image> <title>Steve's News</title> <url>http://www.rssmaniac.com/steve/Image.jpg</url> <link>http://www.rssmaniac.com/steve</link> <description>Steve's News</description> <width>144</width> <height>36</height> </image> . . . </channel> </rss> Note NewzAlert Composer uses the XML <!CDATA ]]> element to store text data. Elements tell the software, such as RSS readers, that is checking your RSS documents not to check their content. In other words, the content of <!CDATA ]]> elements is considered simple text data. Although many RSS creator programs surround text with <!CDATA and ]]> , you can safely omit this markup when writing your own RSS document, because RSS readers are smart enough not to need it. Each of the items in the feed is stored in an <item> element. An <item> element contains these elements:
Here's what these elements look like in the single <item> element: <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <generator>NewzAlert Composer v1.70.6, Copyright (c) 2004-2005 Castle Software Ltd, http://www.NewzAlert.com</generator> <lastBuildDate>Thu, 08 Dec 2005 14:01:27 -0500</lastBuildDate> <pubDate>Thu, 08 Dec 2005 14:01:34 -0500</pubDate> <title>Steve's News</title> <description><![CDATA[This feed contains news from Steve!]]></description> <link>http://www.rssmaniac.com/steve</link> <language>en-us</language> <copyright>(c) 2006</copyright> <managingEditor>Steve</managingEditor> <image> <title>Steve's News</title> <url>http://www.rssmaniac.com/steve/Image.jpg</url> <link>http://www.rssmaniac.com/steve</link> <description>Steve's News</description> <width>144</width> <height>36</height> </image> <item> <title>Steve shovels the snow</title> <description><![CDATA[It snowed once again. Time to shovel!]]></description> <pubDate>Thu, 08 Dec 2005 08:39:51 -0500</pubDate> <link>http://www.rssmaniac.com/steve</link> </item> </channel> </rss> Now that you have an overview of how an RSS 2.0 document works, it's time to start creating an RSS feed. |