[microformats-discuss] A 10 line script to identify and process
any microformat
Alf Eaton
alf at hubmed.org
Thu Jul 28 17:48:26 PDT 2005
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.
More information about the microformats-discuss
mailing list