N3inHTML

From W3C Wiki

N3 in HTML

A method for embedding Notation3 (and its dialects Turtle, N-Triples, etc) in (X)HTML.

Embedding a Graph

Use the HTML script element and a media type of text/n3, text/turtle or text/plain. The id attribute names the graph (you'll see this is useful later). This attribute is invalid in HTML4 but valid in XHTML and drafts of HTML5.


<script type="text/turtle" id="graph1"><![CDATA[
   @prefix foo:  <http://www.example.com/xyz#> .
   @prefix gr:   <http://purl.org/goodrelations/v1#> .
   @prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
   @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

   foo:myCompany
     a gr:BusinessEntity ;
     rdfs:seeAlso <http://www.example.com/xyz> ;
     gr:hasLegalName "Hepp Industries Ltd."^^xsd:string .
]]></script>


Referring to a Graph from Another Graph

The id attribute gives a graph a URI, which can be used in other graphs to refer to it:


<script type="text/turtle" id="graph2"><![CDATA[
   @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

   <#graph1> rdfs:comment "Not sure this is true. It seems like just example data." .
]]></script>


Endorsing a Graph

The page itself can endorse a graph -- i.e. indicate that the graph is believed to be true and relevant to the page using an HTML link element with rel="meta".


<link rel="meta" href="#graph2" />


(Note that the usual type attribute is omitted, as it would simply duplicate the media type already present on the script element.)

Contrasted with RDFa

This method differs from RDFa and some other methods for embedding RDF in HTML.

  • It's a multi-graph technique.
  • The RDF is hidden from browsers. (RDFa is usually used to make text that's already human-readable machine-readable too.)
  • Plain old N-Triples can be easily dumped into the HTML without worrying about splitting predicates into prefix:suffix pairs, and without worrying about how to format it to look good for human readers.

Implementations

Producers

Consumers

Yes, oh yes.

Volunteers sought! Anyone want to write an XSLT that takes XHTML as input and outputs a Turtle file containing any embedded data? Should be pretty easy - just concatenate any data found. Only gotcha is to make sure @base declarations don't leak from one <script> element to another.

People Interested in this Format

seeAlso

Turtle in HTML and auto conversion to JS objects for use in docs