A Developer's Introduction to Microformats - ' Why bother' (
Page 4 of 4 )
?">
Why Microformats?
Having an understanding of what microformats are does not necessarily provide an understanding of why microformats. Why should content publishers and developers care about microformats?
Microformats represents the next step in the evolution of web publishing. They provide a means for content publishers to publish rich information without relying on centralized services. This gives publishers more control over their information, rather than having such data stored in isolated silos.
For example, rather than relying on some centralized calendar service, a person could, in theory, display a series of hEvents on her own blog; they could be imported into her friend's microformat-enabled calendaring software. As microformats catch on, there will be more and more services built around various formats.
I thought XML was supposed to do all this?
You might wonder why you shouldn't choose XML to represent data instead of microformats. This is actually the subject of ongoing debate. However, microformats enjoy several key advantages over embedding XML in web pages.
The first advantage is that microformats already have a very specific task in mind when created and build upon prior work. This helps to avoid the extremely large and complicated specs that have become associated with XML languages.
Another advantage is the reduction of redundancy in the sources of data, as mentioned in the section on designing for humans first. There is no need for one format of the data for humans and another format for machines.
Another form of redundancy that microformats avoid has to do with the fact that in XML and other formats, elements may only have one name. To illustrate this point, let’s take a look at an extremely simple example. The following is an example of the vCard format which is neither XML nor a microformat.
BEGIN:VCARD
VERSION:3.0
N:Haack;Phil
FN:Phil Haack
URL:http://haacked.com/
ORG:VelocIT
END:VCARD
Note that the data of my name is repeated twice. Once for the N element and again for the FN element.
The hCard examples given in the microformats wiki demonstrate how microformats can eliminate redundancy.
<div class="vcard">
<a class="url" href="http://haacked.com/">
<span class="fn n">
<span class="given-name">Phil</span>
<span class="family-name">Haack</span>
</span>
</a>
<div class="org"><span class="organization-name">VelocIT</span></div>
</div>
This microformat translation of the vCard format only needs to specify my name once, by applying multiple “element names” to the span that contains my name.
“Elements” in microformats are specified within attributes as a set of space separated “element names”. Thus a single piece of data in the markup can be shared with multiple elements, reducing redundancy.
Disadvantages of Microformats
As Mark Pilgrim notes in his blog post, Syndication is not Publication, every format has its strengths and weaknesses. One potential microformat weakness is perhaps a consequence of reducing redundancy via the principle of designing for humans first and machines second. Syndicating microformats requires much more bandwidth than the equivalent RSS feed. This could be a serious tradeoff.
Right now, the Microformat movement is dealing with a bit of a the chicken or the egg problem, due to a lack of tools and software built around it. Without tools that make microformat creation simple for content publishers, and to make microformats more usable and visible to content consumers, it is difficult to see the point of the effort.
That is quickly changing as microformats grow in popularity. More and more developers are building tools for content producers and content consumers.
A Few Examples
Before you get started with microformats, it may help to look at various demonstrations and tools that consume microformats, and highlight their usefulness.
Live Bookmarks: One recent and exciting demonstration of what can be done with microformats is the Live Clipboard presentation given by Microsoft CTO
Ray Ozzie. Live Clipboard is a
DHTML control that provides copy and paste functionality for content on the web using an XML data format. Notable in Ozzie’s demonstration is the combination of Live Clipboard and the
hCard and
hCalendar microformats.
Greasemonkey Scripts:
Greasemonkey is a Firefox extension which lets you add bits of DHTML to any web page to change its look or behavior.
The Community Engine site features several Greasemonkey scripts that pertain specifically to microformats. The
xfolk-colorize script searches for sections within a web page formatted using the xFolk microformat and changes the background color to red. The Greasemonkey scripts puts the impetus on the user to highlight microformatted content. They require that user install a plugin so that they can see visual indicators of microformatted content.
Markup Based Javascript Effect Libraries: Another approach is for content producers to use
markup based JavaScript effect libraries. These are javascript files (often working in tandem with a
CSS file) that add various effects to HTML pages based on the markup. Since these scripts are referenced to in the content, the reader does not need to install any special plugins.
One example of this approach is the XFN Highlighter script, written by the author of this article. This script attaches a method to the onload event of the page that dynamically adds CSS classes to links formatted with the XFN microformat (as in the example presented earlier). Combined with a CSS stylesheet, the script adds an icon next to each XFN link and a mouseover tooltip which displays a list of the declared relationships.