[microformats-discuss] A 10 line script to identify and process any microformat

Bud Gibson bud at thecommunityengine.com
Thu Jul 28 19:13:38 PDT 2005


Alf:

I realized the xpath selector was imperfect in this way but figured  
the types of cases you mentioned would be rare enough to just ignore.

A nitpicking issue with your solution is that it assumes people are  
using class attribute values. I suppose that could be fixed easily  
enough.

Would you mind if I made an update to my post mentioning the issue  
you raise and your solution for how to avoid it?  I think it could  
arise in other circumstances that I cannot think of off the top of my  
head, and I'd like people to be aware of the workaround.

Bud

On Jul 28, 2005, at 20:48, Alf Eaton wrote:


> On 29 Jul 2005, at 01:06, Bud Gibson wrote:
>
>
>
>> Dear all:
>>
>> I've been inspired by various microformat scripting efforts (in  
>> particular George Hotelling's) and have come up with a 10 line  
>> greasemonkey script that can identify and process any  
>> microformatted content.  You can access the script here:
>>
>> http://thecommunityengine.com/resources/xfolk-colorize.user.js
>>
>>
>
> Unfortunately, your XPath selector will also match classNames like  
> mixfolkentry, boxfolkentry and xfolkentry2.
>
> This is what I'm using:
>
> -------------
>
> var mf = 'hreview';
>
> var micropath = "//*[contains(@class,'" + mf + "')]";
> var micromatch = new RegExp('\\b' + mf + '\\b');
>
> var mc = document.evaluate(micropath, document, null,  
> XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
> for (var i = 0; i < mc.snapshotLength; i++) {
>     iNode = mc.snapshotItem(i);
>     if (iNode.className.match(micromatch))
>         doSomething();
> }
>
> -------------
>
> The problem with all of these approaches is that once you want to  
> parse or extract more than one microformat, you have to check each  
> element of the page for each of a big list of possible classnames.  
> I'd like to propose, therefore (and maybe it's been proposed  
> before), that each microformat should have one common classname:  
> 'microdata', say. Then the main selector can be
> var mc = document.evaluate(//*[contains(@class,'microdata')]",  
> document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
> and you only have to check the big list of possible classnames  
> against that one node.
>
> For example, <div class="microdata xfolkentry"> or <div  
> class="microdata hreview"> .
>
> alf.
>
> _______________________________________________
> microformats-discuss mailing list
> microformats-discuss at microformats.org
> http://microformats.org/mailman/listinfo/microformats-discuss
>
>
>




More information about the microformats-discuss mailing list