Using Code
Using Microformat Shiv to parse microformats is relatively easy. There are just a few things to note. First is that the format name capitalization is important. If you use the wrong case when specifying which microformat to use the parser will not work. Secondly the DOM node has to contain the microformat node it cannot itself be a microformat node. Last, is that you need to make sure you use the right combination of JavaScript files.
Code example to parse the hCard
<script src="shiv/microformats-shiv.min.js"></script>
<script src="shiv/microformats-coredefinition.min.js"></script>
<script>
var domNode = document.getElementById('hcard-example');
var jsonObject = navigator.microformats.get('hCard', domNode);
alert(JSON.stringify(jsonObject));
</script>
Code example to parse the hResume
<script src="shiv/microformats-shiv.min.js"></script>
<script src="shiv/microformats-coredefinition.min.js"></script>
<script src="shiv/microformats-hresumedefinition.min.js"></script>
<script>
var domNode = document.getElementById('hresume-example');
var jsonObject = navigator.microformats.get('hResume', domNode);
alert(JSON.stringify(jsonObject));
</script>
Files
Microformat Shiv is broken into a number of components so that you only need to load the elements required.
- microformats-shiv.min.js
- The main microformats parser - is always required
- microformats-coredefinition.min.js
- Containing the definition for parsing hCard, hCalendar, XFN, adr, geo and tag microformats.
- microformats-hresumedefinition.min.js
- Containing the definition for parsing the hResume microformat.
- microformats-hreviewdefinition.min.js
- Containing the definition for parsing the hReview microformat.
- microformats-hatomdefinition.min.js
- Containing the definition for parsing the hAtom microformat.
- microformats-isodate.min.js
- Used to convert the ISO date format used in microformats into a native JavaScript date.
- microformats-vcard.min.js
- Used to convert a microformat shiv hCard JSON object into a vcard text string.
- microformats-ical.min.js
- Used to convert a microformat shiv hCalender JSON object into an ical text string.
Follow my twitter account for updates: @glennjones