Re: RDFa API for browsers

On Tue, 2009-10-20 at 23:57 -0400, Manu Sporny wrote:
> The conversation started when I pointed out that we might want to
> start focusing on an RDFa API for Javascript running in browsers since
> Mozilla seems to be open to implementing the Microdata API[3]. 

Just some ideas...

// Query the union of all data found on the page:
var r = document.meta().query('SELECT ?foo WHERE ...');

// Just query the data found in RDFa:
var r = document.meta('rdfa').query('SELECT ?foo WHERE ...');
for (var i in r)
{
  // r[i].foo typeof 'RDFNode'.
  if (r[i].foo.type == 'literal')
    window.alert(r[i].foo.datatype);
}

// Get the RDFa data as a RDF/JSON-like object:
var data = document.meta('rdfa').data;

// Get the RDFa data as an array of triples:
var triples = document.meta('rdfa').triples;
for (var i in triples)
{
  // each triple has subject, object, predicate and graph properties
  var g = triples[i].graph; // named graph URI
  var s = triples[i].subject;

  // RDFNode.token returns a Turtle-like token
  // (i.e. URIs in <>, literals in "", bnodes start _:).
  if (s.type != 'bnode')
    window.alert(s.token);
}

// Can also grab data from Microdata and GRDDL if the browser
// supports those.
var data = document.meta('grddl').data;
var r = document.meta('items').query('SELECT ?foo WHERE ...');

-- 
Toby A Inkster
<mailto:mail@tobyinkster.co.uk>
<http://tobyinkster.co.uk>

Received on Wednesday, 21 October 2009 08:49:06 UTC