|
||||||||
XML
|
![]() |
How to extend Radio's RSS generatorStatus![]() This feature has been released. Update Radio to get the latest parts. You may deploy applications that depend on this feature. Background ![]() Radio UserLand generates RSS 2.0 feeds for the main weblog and for each category. These files are updated automatically when the user posts something new or edits an existing post. Until now one could override the built-in RSS generator, but not add to it incrementally. With the changes outlined here, you will be able to add, without wholesale replacement. This is a technical document, only for programmers. Example document ![]() An RSS document illustrates many of the features explained here. Three callbacks ![]() With these callbacks, applications can now: 1. Add namespaces to the <rss> element. 2. Add elements at the <channel> level. 3. Add elements at the <item> level. The callback scripts are in user.radio.callbacks.writeRssNamespace, writeRssChannelElement, writeRssItemElement. Adding a namespace declaration ![]() Scripts go in user.radio.callbacks.writeRssNamespace. They take one parameter, the address of a table, which will contain name-value pairs, where the name is the local name for the namespace, and the value is the global identifier (usually a URL) for the namespace. An example, will add a blogChannel namespace declaration on the <rss> element as illustrated in the example document. ![]() Adding elements at the <channel> level ![]() Scripts go in user.radio.callbacks.writeRssChannelElement. They work the same way as namespace callbacks, with a few additions. A name may contain a colon to indicate that it is part of a namespace. And a name may have a tab, allowing multiple elements with the same name in the RSS file that's generated. First, a straightforward example that adds two elements of the blogChannel namespace to the channel, as illustrated in the example document. ![]() Second, a whimsical example that adds several <gooey> elements to the channel, to show that it can be done. ![]() Adding elements at the <item> level ![]() Scripts go in user.radio.callbacks.writeRssItemElement. They work the same as the <channel> level callbacks, with one exception, the second parameter is the address of the table containing the post. You can use that to get information about the post to include in the RSS feed. The example below adds the unique id of the post, which is determined from the name of the table containing the post. ![]() Elements with attributes ![]() The above works great if all you want to do are elements with no attributes. Okay, but what if you want attributes? Let's see if we can make that work. Try this. Instead of adding a scalar to the table, add a sub-table. For the value, add a sub-element named /value. Add as many other scalars to the table as you like, each of them will be an attribute on the XML that we generate. Here's an example callback script: ![]() And here's the XML that's generated: <person age="39" bodyType="wide" hair="limited">Lawyer Boyer</person> If all you want is attributes, and no value, leave out the /value sub-element. This works at the <channel> or <item> level. Questions, comments, etc ![]() Post comments on the Radio-Dev mail list, or in the discussion group here.
|
||||||
Last update: Tuesday, January 21, 2003 at 8:10:37 AM Pacific. |