An XML feel-good story

Seems like everyone likes to bitch about XML (or WS-*) these days. Today I had a very, very pleasant experience with XML and a few related APIs that saved me a couple of hours (at least) worth of work.

Turns out that I have a good (non-technical) friend named Ben for whom I set up custom, home-grown PHP blogging system sometime around 2002. This was a very basic setup where he could post and others could comment… post archival was very basic and syndication feeds and other blogging niceties were nowhere in sight. At the time Ben and I were very proud of his little blogging setup… back then, blogs (and blogging services/toolkits) were much less prevalent.

Fastforward to 2006 and several of Ben’s fellow non-technical friends now also have blogs thru services such as Blogger, MySpaces and the like… Ben’s blog was now seriously outclassed by the cool features (like syndication) that were offered in these packages by default.

Ben had gone from cutting-edge to behind-the-curve. :(

Clearly it was time to set Ben up with something more modern… I chose Wordpress 2.0 since that is what I am using for this blog, and I’m pretty fond of it.

So the big hurdle was how to migrate roughly 700 blog postings from my crufty old custom MySQL tables into a WordPress 2.0 blog with minimal effort.

XML provided a simple, elegant solution.

I noticed WordPress’ admin dashboard included an ‘Import’ tab with various options for including db tables from other blogging packages, CSV, and finally from an RSS 2.0 feed.

Hmmm… If I could just get a complete RSS 2.0 feed of all previous posts from Ben’s blog, looks like I could import it very easily. Let’s look at Ben’s old MySQL tables using PHPMyAdmin… Wait… here’s an option to dump a table to an “XML File”.

Ding!!!!

The entire process took about 5 minutes:

  1. Export old MySQL table to Plain-Ole-XML file.
  2. Look at POX file.
  3. Look up RSS 2.0 feed example (they’re everywhere!).
  4. Write brief XSLT stylesheet (using AquaXSL) that transforms POX file to RSS 2.0
  5. Import RSS 2.0 version of all blog posts using WP “import RSS 2.0″ feature.

Not a single line of code written. XSLT doesn’t count… it’s declarative :)

Some of you may be saying… wait a minute… XML and XSLT weren’t the only things that made this easy… PHPMyAdmin and WordPress helped too…

Well, yeah… kinda… but in the end it was the ubiquity and wide-ranging acceptance of XML as a data interchange format and the availability of high-level XML-related APIs that made this transition completely painless.

Yay, XML.

Leave a Reply