Daemonite: Building RDF feeds in CFMX Archive

Daemonite: Building RDF feeds in CFMX Archive


Tuesday, January 21, 2003
Building RDF feeds in CFMX

I've spent some time playing with RSS/RDF XML this year playing with http://fullasagoog.com/. Recently, I released a series RDF feeds for the blogs syndicated at Fullasagoog to make life easier for folks with NewsAggregators and several groups who just wanted some of their blogs mixed into a single file.

I thought I might take the time to show just how easy it is to generate XML feeds in CFMX. CFMX comes with some great XML tools built-in, but funnily enough I found myself just playing with tags you'd find in much earlier versions of CF. So If you're still running an old clapped-out version of the server, a bit of tweaking would still get this code running.

Firstly, I'm working with RDF 1.0 which is a syndication format I prefer. It's less popular than earlier RSS 0.91-92 formats but it includes a timestamp and categorisation in the feed which I find very useful in a place like Fullasagoog.

The following is a sample RDF feed from the Fullasagoog on Dreamweaver. There's really only three parts to it: a description of the feed, the "channel" and the individual content items.

You can torture yourself with descriptions of the RSS/RDF formats here:

Rather than getting into a full blown essay on XML formats and the like, I've only got time to run through the code snippets I used to generate the XML and provide a little bit of comment here and there. Hopefully, you'll get the gist. In any event rehashing someone elses working feed is probably the best place to start.

First up I'm using CFSAVECONTENT to capture the resulting XML output. I could have used CFXML, but for some reason I was getting a NULL written to my feed file when using the toString() function, even though the XML document object was validating correctly. No time to decipher what was going on there - so I went with CFSAVECONTENT.

Next I build the "channel" with a simple mixture of local variables (eg. cat for category) and a query object (qBlend) I created earlier.

Next up is another standard CFOUTPUT looping over the qBlend query again. Just filling in the gaps. A note for beginners; you must convert extended characters to something harmless. Being a lazy sod, I hunted about on http://cflib.org/ and found ConvertEntity() by Mike Gillespie. So far it has worked a treat.

Last of all I just output something to the screen for testing. It's a bit of legacy debugging code really, but I parse the CFSAVECONTENT result into an XML Object and confirm that it validates, then write the XML object to the disk. This is where I was getting the weird string "NULL" being written when I replace CFXML instead of CFSAVECONTENT. No error... just "NULL" instead of my XML packet. Would be interested to hear if anyone else can replicate that issue.

Before I sign off for the night, it wouldn't be fair if I didn't point to the secret of my validating RSS success: RSS Validator. It's a great resource that pinpoints and details exactly where your feed is going wrong.

Posted by modius at 10:55 PM | Permalink
Trackback: http://blog.daemon.com.au/cgi-bin/dmblog/mt-tb.cgi/75

Comments

Just a note for those fiddling with their first bits of RSS... beware CF's whitespace issues. Some validators won't mind if you have a space or line preceding the XML declaration at the top of an RSS 0.91/0.92/2.0 feed, but many of them will throw errors. More significantly, any tools or services that rely on such validators will error out, causing you problems with sites like Syndic8.

Posted by: Roger on January 22, 2003 01:00 AM