[uf-discuss] Parsing XFN in PHP

Daniel O'Connor daniel.oconnor at gmail.com
Tue Apr 8 07:09:03 PDT 2008

On Tue, Apr 8, 2008 at 9:40 PM, Julian Bond <julian_bond at voidstar.com> wrote:
> I need some advice about reading rel="me" tags in arbitrary web pages using
> PHP. I'm intending to use this to help build a lifestream style function.
> The basic intent is to cut down the amount of data entry the user has to do.
> When they give me a MyBlogLog, Friendfeed, Plaxo Pulse page that has lists
> of links to their profile pages I should be able to avoid having to ask them
> for all of them again. So:-

See also http://code.google.com/p/xmlgrddl/


//Load a GRDDL engine
$grddl = XML_GRDDL::factory('xsl');
$xml = $grddl->fetch($url);

//Look for GRDDL transformations to extract out any data at those URLs
$stylesheets = $grddl->inspect($url);
$stylesheets[] =
'http://www.w3.org/2003/12/rdf-in-xhtml-xslts/grokXFN.xsl'; //Force
XFN to apply

$rdf_xml = array();
foreach ($stylesheets as $stylesheet) {
    $rdf_xml[] = $grddl->transform($xml, $stylesheet);

//Produce One True RDF/XML document
$result = array_reduce($rdf_xml, array($grddl, 'merge'));

$document = simplexml_load_string($file);
$document->registerNameSpace('vcard', 'http://www.w3.org/2006/vcard/ns#');
$links = $document->xpath('//rdf:homepage');

//Present this list of links to the user for selection ("hey, those
are my links' or "that's my friend's link")

A little verbose, and a little fragile, but it should work

More information about the microformats-discuss mailing list