The following post was originally written in August of 20066. For some reason I never posted it to the blog, though reading it now it seems interesting. It’s fairly technical, unlike some of the other posts. Hope you enjoy it:

I wasn’t sure how to best link in our new blog. After thinking about it a while I decided that a little box in the corner of the site could list the last 2 or 3 blog posts. I then figured I should be able to list the last forum posts too. Once I had the idea, I had to figure out how I was going to get the info from two diverse pieces of code into our green felt page template.

Then I noticed that the blog we set up (wordpress) has an RSS feed. This is a little XML data file that always has the latest posts in it. Nice. The forum didn’t have any RSS support though. Luckily, it’s one of the most popular forums out there so there were at least 3 add-ons that would add RSS functionality. It took me 2 tries to get a good one, but in the end I liked the way it worked. I was able to customize it and add in a couple XML fields that they didn’t set by default.

After seeing how slow the RSS feeds were to respond I decided that it would be best for the client to go get the data and transform it onto the screen. Nobody wants to wait 2 extra seconds for their page to load just for some integrated RSS.

I then had to coax the XML from the RSS into a form that could be displayed on the page. I started with the standard javascript DOM interface, but it was a big pain and the code was growing way too big way too fast. I then realized that it would be best to parse it on the server side and send JSON over to the javascript client. So it was time for a quick CGI script.

Let’s hear it for perl! I whipped up something that parsed the XML adequately in about 5 minutes. The key to the whole script is this line here:

print objToJson(XMLin($response->content, ForceArray=>["item", "channel"]));

That uses perl’s XML::Simple to parse the XML into a perl structure. The “ForceArray” part makes sure that all the “item” and “channel” tags in the XML get interpreted as array items. It then outputs that structure as JSON, ready to be interpreted by the javascript side.

The javascript side is easy since it has everything in a native structure. Want the title of the first item in the first channel?[0].item[0].title. Once I had the right data structures, the rest of the code basically wrote itself.

In the end I’m happy with the way the code turned out, but I’m not sure whether an extra little box in the corner of the page use useful enough to balance out the amount of clutter it adds.