October 30, 2007
Posted by Eddie
Microformats for you and me
After nearly 3 months sitting on my bookshelf, I got around to reading the Microformats book. I probably don’t need to mention that they’ve been pretty high on the “buzz†list for a while now. That aside, I like the idea, and believe they are worth using. With this post, I hope to give a high-level overview of Microformats… first sampling what they are and how to use them, followed by my thoughts on why you should use them.
What and How
Very simply, Microformats give our already semantic xhtml elements an extra layer of meaning when using a common set of attribute values. Consider the case of an “hCalendarâ€, a microformat that gives xhtml the structure of an events calendar. An events calendar is simply a set of events. This relationship is easily described by a parent-children relationship. The problem is that xhtml can easily describe parent-children relationships, yet it cannot semantically describe this calendar-events relationship. Microformats do just that… they provide a way to describe this common relationship through the use of attribute values.
To create an “hCalendarâ€, you would write something like the following:
<div class=â€vcalendarâ€>
<span class=â€veventâ€/>
<div class=â€veventâ€/>
<dl class=â€veventâ€/></div>
As you can see, the supplementary calendar-events structure is added by setting specific attribute values, in this case ‘vcalendar’ and ‘vevent’. Microformats use exiting attributes like ‘class’ and ‘rel’ as hooks for this structure, in the same way these attributes can be used as hooks for additional CSS information. Additionally, these attributes can be applied to whichever element you choose*. I demonstrated the use of the same attribute/value pair (class=â€veventâ€) on the ‘span’, ‘div’, and ‘dl’ elements in the example above.
[* The rules for applying attributes to elements are the same as the existing xhtml spec]
Why you should use them
While I foresee a wide array of future uses for Microformats, there are limited practical applications today. That being said, the small number does not mean they have limited value; their use can provide substantial value. For example: later this week I am going to re-write the concert-listing page for my orchestra website. I am going to use the hCalendar Microformat to code this season’s events. I will then use an open-source converter to allow users to download a iCal file of this calendar on the fly.
Why would I do this? Because it’s advantageous. Using the hCalendar Microformat I can…
- provide an additional interface (the iCal file) to my users for free.
- syndicate these events. That way, if I ping a Microformat aware service (like pingerati.net) I will have published these events elsewhere, without any additional work.
- maintain only one source file for multiple outputs (in this case, html, iCal file, and syndicated content)
- use my current knowledge of html as a base for the syntax, requiring me only to learn the Microformats terms and schema before I start using them
There are similar uses for the other Microformats, including hCard (contact info), geo and adr (location/address), XFN (relationships between people), and so on. I invite you to take a look at the book or the Microformats website for more information.
I hope that’s enough to convince you that Microformats are a valid and useful technology. One of the more compelling aspects is the way Microformats are created, yet I think that is interesting enough to warrant it’s own post (look for it later). Hope someone out there finds this useful.
No Comments Yet
You can be the first to comment!
Leave a comment
You must be logged in to post a comment.