[uf-discuss] Automated microformat parsing using XPath

Matt Augustine matta at microsoft.com
Wed Aug 9 14:06:03 PDT 2006

I have written simple parsers for hCard and hCal in javascript that use
XPath to parse the microformat properties from an arbitrary xhtml
document.  In general, for each known property I have code like this:

node = document.evaluate("//*[contains(@class,
'vevent')]//*[contains(@class, 'description')]", hCalXmlNode, null, 0
/*XPathResult.ANY_TYPE*/, null).iterateNext();

if (node) {self.Description = node.textContent;}

This works great in most cases, but I'm having trouble with the case
where the exact location of the data (which attribute, inner element
etc.) is unknown.  For example, UIDs might be represented as:

<a rel="contact friend" class="url uid fn"

How would I parse the value without special casing to look in the href
attribute if the containing element is an <a>?  An XPath expression like
the one above would yield "fiahless" instead of

Matt Augustine

More information about the microformats-discuss mailing list