W3C

RDF/A Primer 1.0

Examples of RDF/A Applied to XHTML2

note 27 October 2005

This version:
http://www.w3.org/2001/sw/BestPractices/HTML/2005-rdfa-primer
Latest version:
http://www.w3.org/2006/07/SWD/RDFa/primer
Previous version:
none
Editor:
Ben Adida, Creative Commons <ben@creativecommons.org>

Abstract

The aim of this document is to introduce the RDF/A syntax for adding RDF triples to XML dialects. Examples are provided in the context of XHTML2, the most immediate such XML dialect. The reader is expected to be fairly familiar with XHTML, and somewhat familiar with RDF.

Status of this Document

This is an internal draft produced by the RDF-in-HTML task force [RDFHTML], a joint task force of the Semantic Web Best Practices and Deployment Working Group [SWBPD-WG] and HTML Working Group [HTML-WG].

Last Modified: 2005-10-27

Table of Contents

1 Purpose of RDF/A
2 Simple Metadata
    2.1 Textual Properties
    2.2 Qualifying Links
3 Beyond the Current Document
    3.1 Qualifying Other Documents
    3.2 Qualifying Chunks of Documents
    3.3 Syntactic Sugar
    3.4 Inline Objects
4 Advanced RDF Concepts
    4.1 Bnodes
    4.2 Reification
5 Practical Examples
    5.1 Creative Commons
    5.2 FOAF
6 Bibliography


1 Purpose of RDF/A

RDF/A is a set of attributes that are used to augment existing XML dialect elements with RDF metadata. The primary goal of RDF/A is to embed RDF without repeating existing content of the XML dialect when that content is the metadata. This document will specifically consider XHTML2 as a host XML language, as that was the primary target for RDF/A. However, one should be able to use RDF/A with other XML dialects, e.g. SVG.

We note that RDF/A makes use of XML namespaces. In this document, we assume, for simplicity's sake, that the following namespaces are defined: dc for Dublin Core, foaf for FOAF, and cc for Creative Commons.

2 Simple Metadata

2.1 Textual Properties

Consider a simple XHTML2 document fragment:

<h1>RDF/A Examples</h1>
<h2>Ben Adida</h2>

The rendered information about the document, specifically its title and author, can be easily marked up as RDF properties:

<h1 property="dc:title">RDF/A Examples</h1>
<h2 property="dc:creator">Ben Adida</h2>

which provides the following RDF triples:

<> dc:title "RDF/A Examples" .
<> dc:creator "Ben Adida" .

2.2 Qualifying Links

Consider an XHTML2 document fragment that links to a copyright license defining its terms of redistribution:

This document is available under a
<a href="http://creativecommons.org/licenses/by-nc-nd/2.5/">
  Creative Commons License
</a>.

This clickable link has an intended semantic meaning: it is the document's license. RDF/A quickly allows for the typing of this clickable link:

This document is available under a
<a rel="cc:license"
   href="http://creativecommons.org/licenses/by-nc-nd/2.5/">
  Creative Commons License
</a>.

In RDF/A, the href attribute can contain a Compact URI (CURIE), which makes the expression of numerous metadata statements far more compact. To differentiate the CURIE from a typical URI, we use square brackets (as per [CURIE]).

This document is available under a
<a xmlns:cclicenses="http://creativecommons.org/licenses/"
   rel="cc:license"
   href="[cclicenses:by-nc-nd/2.5/]">Creative Commons License</a>.

Both of these RDF/A-augmented snippets of XHTML yield the following triple:

<> cc:license <http://creativecommons.org/licenses/by-nc-nd/2.5/> .

3 Beyond the Current Document

The above examples casually swept under the rug the issue of the RDF triple subject. However, not all RDF triples in a given XHTML2 document will be about that document itself. Without any further guidance, the subject of an RDF/A assertion defaults to the current document. However, there are easy ways to override this default.

The about attribute is used for defining the subject.

3.1 Qualifying Other Documents

One may wish to make metadata statements about other documents altogether. This is particularly useful in the case of inline images:

A bunch of photos:
<ul>
  <li> <img src="photo1.jpg" /> taken by photographer 
       <span about="photo1.jpg" 
             property="dc:creator">Mark Birbeck</span></li>

  <li> <img src="photo2.jpg" /> taken by photographer 
       <span about="photo2.jpg" 
             property="dc:creator">Steven Pemberton</span></li>
</ul>

The above XHTML2 and RDF/A yield the following triples:

<photo1.jpg> dc:creator "Mark Birbeck" .
<photo2.jpg> dc:creator "Steven Pemberton" .

This same approach applies to statements with non-literal objects. For example, a photo might have its own copyright license:

A bunch of photos:
<ul>
  <li> <img src="photo1.jpg" /> taken by photographer 
       <span about="photo1.jpg" 
	     property="dc:creator">
	 Mark Birbeck
       </span>,
       licensed under a
       <a about="photo1.jpg" rel="cc:license"
	  href="http://creativecommons.org/licenses/by-nc-nd/2.5/">
	 Creative Commons License
       </a>.
  </li>
...

Considering only this single photo (photo1.jpg) in the above example, the following triples are obtained:

<photo1.jpg> dc:creator 
             "Mark Birbeck" .
<photo1.jpg> cc:license 
             <http://creativecommons.org/licenses/by-nc-nd/2.5/> .

Note that the about attribute is repeated in the above example. RDF/A allows the value of this attribute to be inherited from parent elements. Thus, the markup for the above example can be simplified to:

A bunch of photos:
<ul>
  <li about="photo1.jpg"> <img src="photo1.jpg" />
    taken by photographer 
    <span property="dc:creator">Mark Birbeck</span>,
    licensed under a
    <a rel="cc:license"
       href="http://creativecommons.org/licenses/by-nc-nd/2.5/">
      Creative Commons License
    </a>.
  </li>
...

which yields the same triples as the previous example, though, in this case, one can easily see the parallel to the corresponding N3 shorthand:

<photo1.jpg> dc:creator "Mark Birbeck" ;
             cc:license <http://creativecommons.org/licenses/by-nc-nd/2.5/> .

3.2 Qualifying Chunks of Documents

In certain cases, one wants to include multiple RDF elements in a given document, each with their own type and metadata. It's also important to be able to relate them. The prime example of this is FOAF.

For this purpose, RDF/A offers link and meta, which behave in a special way : they only apply to their immediate parent element.

<section id="person">
  <link rel="rdf:type" href="[foaf:Person]" />
  <h1 property="foaf:name">Dan Brickley</h1>
  <link rel="foaf:homepage" href="" />
</section>

which yields:

<#person> rdf:type foaf:Person ;
          foaf:name "Dan Brickley" ;
          foaf:homepage <> .

Alternatively, if one wishes to express this same metadata about #person without actually having that chunk of HTML represent the person in question, then one can write:

<section about="#person">
   <link rel="rdf:type" href="[foaf:Person]" />
   <meta property="foaf:name" content="Dan Brickley" />
   <link rel="foaf:homepage" href="" />
</section>

This yields the exact same triples. Note how the meta and link apply to the parent node's about if that about exists.

3.3 Syntactic Sugar

@@TODO: finalize whether this is acceptable syntactic sugar

Extrapolating from the above examples, it's quite easy to see how XHTML elements might represent RDF entities on a regular basis. Thus, RDF/A offers syntactic sugar for the rdf:type relationship, using the well-established class attribute. The above XHTML2 can thus be simplified to:

<section about="#person" class="[foaf:Person]">
   <meta property="[foaf:name]" content="Dan Brickley" />
   <link rel="[foaf:homepage]" href="" />
</section>

3.4 Inline Objects

@@TODO: this issue is not yet resolved: Current Issues. And there are some weird consequences: the inside of the img element is not rendered, so what of renderable XHTML elements with metadata? We may want to only enable link and meta...

Images and Objects in XHTML2 are loaded from the src attribute. Adding some metadata relevant to these inline objects is a natural extension of previous examples. In the absence of an about attribute, the src attribute serves as the subject. For example, the following XHTML with RDF/A:

<img src="photo1.jpg">
   <link rel="cc:license" 
	 href="http://creativecommons.org/licenses/by-nc-nd/2.5/" />
   <meta property="dc:creator" content="Mark Birbeck" />
</img>
  

which yields the following triples:

<photo1.jpg> cc:license <http://creativecommons.org/licenses/by-nc-nd/2.5/> ;
             dc:creator "Mark Birbeck" .
  

4 Advanced RDF Concepts

4.1 Bnodes

The progression to bnodes is natural. In the above examples of Section 3 where link and meta are used to attach metadata to their parent element, one wonders what would happen if the parent element had neither id nor about attribute. The result is exactly a bnode: an XHTML element that isn't addressable from the outside:

<section>
   <link rel="rdf:type" href="[foaf:Person]" />
   <h1 property="foaf:name">Dan Brickley</h1>
   <link rel="foaf:homepage" href="" />
</section>

Alternatively, one can make the about an explicit bnode using the CURIE notation:

<section about="[_:person]">
   <link rel="rdf:type" href="[foaf:Person]" />
   <h1 property="foaf:name">Dan Brickley</h1>
   <link rel="foaf:homepage" href="" />
</section>

Both of these yield:

_:person rdf:type foaf:Person ;
         foaf:name "Dan Brickley" ;
         foaf:homepage <> .

(Technically, it's unlikely that the first would magically yield a bnode name of _:person. It would likely be something like _:section0. But the result is really the same.)

4.2 Reification

When a meta or link is used within another meta or link, the internal triple has, as subject, the external triple. This is reification.

<link about="" rel="cc:license" 
      href="http://creativecommons.org/licenses/by-nc-nd/2.5/">
   <meta property="dc:date" content="2005-10-18" />
</link>

which yields:

[ rdf:subject <>;
  rdf:predicate cc:license ;
  rdf:object <http://creativecommons.org/licenses/by-nc-nd/2.5/> ]
dc:date "2005-10-18" .

5 Practical Examples

5.1 Creative Commons

Describing the licensing of a document with Creative Commons metadata is, in some sense, an extension of Dublin Core, since Creative Commons usually hands out a number of Dublin Core attributes in addition to the license relationship. Thus, a Creative Commons RDF/A chunk would be:

<div about="">
    This document is licensed under a
    <a rel="cc:license" 
       href="http://creativecommons.org/licenses/by-sa/2.0/">
        Creative Commons License
    </a>
    which, among other things, requires that you provide 
    attribution to the author,
    <a rel="dc:creator" 
       href="http://ben.adida.net">Ben Adida</a>.
</div>
            

which will generate:

<> cc:license <http://creativecommons.org/licenses/by-sa/2.0/>
<> dc:creator <http://ben.adida.net>
            

5.2 FOAF

FOAF requires the definition of at least two RDF entities: the FOAF person, and the FOAF homepage, which cannot be the same. Thus, the following XHTML can be used to represent a FOAF record:

<html xmlns...>
    <head>
      <title property="dc:title">Dan's home page</title>
    </head>
    <body>
      <section id="person">
        <span about="[_:geolocation]">
          Dan is located at latitude
          <meta property="geo:lat">51.47026</meta>
          and longitude
          <meta property="geo:long">-2.59466</meta>
        </span>
        <link rel="rdf:type" href="[foaf:Person]" />
        <link rel="foaf:homepage" href="" />
        <link rel="foaf:based_near" href="[_:geolocation]" />
        <h1 property="foaf:name">Dan Brickley</h1>
      </section>
    </body>
</html>
            

which yields the correct FOAF triples:

<> dc:title "Dan's home page" .
_:geolocation geo:lat "51.47026" .
_:geolocation geo:long "-2.59466" .
<#person> rdf:type foaf:Person .
<#person> foaf:homepage <> .
<#person> foaf:based_near _:geolocation .
<#person> foaf:name "Dan Brickley" .
            

6 Bibliography

RDFHTML
RDF-in-HTML Task Force (See http://w3.org/2001/sw/BestPractices/HTML/.)
SWBPD-WG
Semantic Web Best Practices and Deployment Working Group (See http://w3.org/2001/sw/BestPractices/.)
HTML-WG
HTML Working Group (See http://w3.org/MarkUp/Group/.)