HellOnline

Icon

Eran's blog

miniProject: Microformat Autopopulation

I’ve been thinking about various ways to parse microformat data into an object. There’s plenty of ways to tackle this problem but most require a different script for every microformat standard. The alternative that’s most alluring to me is reflection – learning the schema and values of a piece of data and automagically creating the appropriate object populated with the correct values. I started working on something similar to the database refelction used in Ruby on Rails but soon stopped and limited the scope of the project. Since most microformats still lack a proper schema and since the XHTML structure lacks definite data on the internal structure of the object, full reflection is a complicated affair and might not even be possible. I chose to use an existing schema (database tables and module files) and to limit myself to autopopulation of the values in objects based on that module. The resulting script (while not complete) contains no specific references to any microformat (with the exception of the schemas, of course). I currently have a schema in place for xFolk RC1 entries and will soon add more.

To play with the current (early!) iteration, go to http://hellonline.com/reflect/public/dispatch.fcgi/xfolkentries/text
(NOTE: this version uses class=”description” instead of class=”extended” as per the recent changes )

How it Works
The script relies on creating well formatted names for properties based on HTML elements information (element name, class name and rel value). Once a name for a possible property has been decided it checks to see if the object in question has a property of this name and sets the value according to the object type (if it exists). Using Ruby it is easy to detect that a certain property is an array and treat it correctly.

Complete source is available but the interesting file is really lib/microformats.rb

Update: The application can now parse (most) hCard data as well. Next in line, hReview.

Advertisements

Filed under: MicroFormats, Projects

%d bloggers like this: