Re: FPWD Review Request: HTML+RDFa

Shane McCarron wrote:
> [...] If you want to implement an RDFa 
> processor such that it is truly namespace aware, discovering the 
> namespace prefix mappings via [in-scope namespaces] property... you are 
> certainly free to do so.  I have yet to find a DOM implementation I can 
> get to in Perl that makes this easy to do (my RDFa processor is written 
> in Perl).

Does XML::LibXML's DOM not make it adequately easy?

   use XML::LibXML;
   my $p = new XML::LibXML;
   my $doc = $p->parse_string('<foo xmlns="http://www.w3.org/...">
     <foo xmlns:ns="http://example.com"><foo/></foo></foo>');
   for my $e ($doc->getElementsByTagName('foo')) {
     print "$e\n";
     for my $ns ($e->getNamespaces) {
       print '  ', $ns->name, ' = ', $ns->value, "\n";
     }
     print '  lookup(ns) = ', ($e->lookupNamespaceURI('ns') || ''), "\n";
   }

(Obviously this won't work if you're constructing a DOM from an HTML 
parser (rather than an XML parser), because the XML Namespaces spec 
doesn't apply to non-XML HTML at all. But when you're doing everything 
with real XML, the namespace mappings should all work easily, as far as 
I'm aware.)

-- 
Philip Taylor
pjt47@cam.ac.uk

Received on Thursday, 3 September 2009 15:59:31 UTC