RDFa Introduction

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!



RDF is an abstract, machine-readable data representation meant to maximize the reuse of vocabularies. RDFa is a way to express RDF data within XHTML, by enriching the existing human-readable data with RDF attributes. RDFa then enables us to bridge the gap between what humans see when viewing a document and what machines "see" when they process the same document. The meaning added by the semantic attributes enables machines to make intelligent assertions on the information found in RDFa-enriched documents.

Back to the top

The RDFa Attributes

RDFa in XHTML makes use of a number of XHTML attributes, as well as providing a few new ones. Attributes that already exist in XHTML will have the same meaning as in XHTML, although their syntax may be slightly modified. For example, in XHTML, @rel already defines the relationship between one document and another.
The XHTML attributes that are relevant are:

a whitespace separated list of CURIEs, used for expressing relationships between two resources ('predicates' in RDF terminology);
a whitespace separated list of CURIEs, used for expressing reverse relationships between two resources (also 'predicates');
a token for expressing a value which is a plain literal (also a 'predicate');
a string, for supplying machine-readable content for a literal (a 'plain literal object', in RDF terminology);
a URI for expressing the partner resource of a relationship (a 'resource object', in RDF terminology);
a URI for expressing the partner resource of a relationship when the resource is embedded (also a 'resource object').

The new RDFa-specific attributes are

a URIorSafeCURIE, used for stating what the data is about (the 'subject' in RDF terminology);
a whitespace separated list of CURIEs, used for expressing relationships between the subject and some literal text (also a 'predicate');
a URIorSafeCURIE for expressing the partner resource of a relationship that is not intended to be 'clickable' (also an 'object');
a CURIE representing a datatype, to express the datatype of a literal;
a whitespace separated list of CURIEs that indicate the RDF type(s) to associate with the subject.

Back to the top

The RDF Vocabularies

One is free to use any RDF vocabulary when adding RDF attributes, even ones created by yourself, but it generally will be most useful to use standard vocabularies which one can expect RDF processors to know about. Some examples are: 

Back to the top

Example: A weblog posting

When viewing a post written by some Drupal user, it is easy for a human being to know that "Submitted by" - "on" - "some date and time" means that somebody wrote and submitted the posting at some date in time, and that that someone is a user in the Drupal system. But to make a machine understand this we will have to tell the machine that there is a relation between this post and a user that has created it. To this we will have to use the rel HTML-attribute which defines a relationship between the post's node and the user's node'

The weblog post itself

In order to relate several items like title, author, submitted date, comments etc. to the weblog post, we need to tell who the subject of these relations is. To do this one uses the @about-attribute and put it on an element that works as a container for all these items. In the case of a Drupal weblog post, it makes sense to put it on the div-element which has the content-id:

	<div id="main-wrapper">
		<div id="main" class="clearfix">

The use of #this as a value for the @about attribute, is just to give the @about-attribute an anonymous value that functions as a marker pointing to the weblog post itself.

Establishing the type of the document

		typeof="foaf:Document sioc:Post" 
		class="node clearfix">

To express that the document is both a document and a weblog post one can use the @typeof-attribute and passing it foaf:Document and sioc:Post as values.

The title

	<h1 property="dc:title"
	               id="page-title">My article </h1>

To indicate that h1 represents the title of the page, one will have to use the @property-attribute, an attribute introduced by RDFa for the specific purpose of marking up existing text in an HTML page. The value used is the title-property of the Dublin Core vocabulary. This will produce the following RDF triple:

See: title_triple.png

Only local images are allowed.

The author and submitted time

	<div class="submitted">
	    Submitted by
		<span rel="sioc:has_creator dc:creator">
			<span property="foaf:name" 
		<span property="dc:created" 
		      content="2009-05-11T10:34:53+00:00">Mon, 05/11/2009 - 10:34</span>.

What happens here ? First of all, we want to create a relationship between the weblog post itself as a subject identified by the @about-attribute described above and the author of the weblog post. This is taken care of by placing rel="sioc:has_creator dc:creator" as attribute on a span which will wrap around information about the author placed in a child element of this span-element. The reason for using both sioc:has_creator and dc:creator is to ensure completeness of the semantics.

The child span-element has two functions, the first is to represent the author object of the "created"-relation. The second is to provide further information about the author itself. This information should be part of a different RDF-triple with the author playing the role of the subject. To do this, one sets a new @about-attribute to set the author as the subject of the resulting RDF-triple.

Then to express the nature of the new subject, one uses the @typeof-attribute with a value of sioc:User, an attribute in the sioc-vocabulary telling us that the creator is a user in Drupal

Lastly, the @property-attribute tells us that the word admin is a name of a person, an attribute in the foaf-vocabulary

See: has_creator.png

See: has_creator_triple.png

Why use dc:creator and dc:title, instead of simply creator and title? As it turns out, HTML does not have reserved keywords for those two concepts. To enforce a modicum of organization, RDFa does not recognize property="title". Instead,we must indicate a directory somewhere on the web, using simply a URL, from where to import the specific creator and title concepts we mean to express.

In RDFa, all property names are really, URLs, but for brevity we use CURIE's which are of the form prefix:reference which will resolve to the full associated URI as long as we import the vocabulary into the document. As an example, when importing xmlns:dc="http://purl.org/dc/elements/1.1/ we associate the URI with the dc prefix, and using dc:title will actually resolve to http://purl.org/dc/elements/1.1/title

The body of the weblog post

		property="content:encoded dc:description" 
	    <p>Lorem ipsum.........</p>

Here we are using content:encoded from the RSS Site Summary Content Module vocabulary together with dc:description to indicate that what follows is the content of the weblog post

The link to the user's weblog

	<li class="blog_usernames_blog first last">
		<a href="/blog/1" 
			  title="Read admin's latest blog entries." 
			  resource="blog/1#this">admin's blog</a></li>	

The @rel-attribute will point back to the weblog itself and create a relationship expressing that the weblog is the container of this link. The @property with a value of dc:title marks up the title of the link.


For each comment there is a need of expressing the relationship between them in terms of what level each comment is a reply to. This can be done using terms from the sioc-vocabulary such as sioc:has_reply and sioc:reply_to.

	 <div id="comments">
	 	<a id="comment-1">
				class="comment comment-published clearfix">

The @rev-attribute is does the same as the @rel-attribute but creates a reverse relation instead. The @revattribute with a value of sioc:reply_of points back to the last @about-attribute which is set on the blog post itself and creates the reverse relation. While the @rel-attribute also points back to the last @about, it creates a forward relation to this comment with a value of sioc:has_reply

The next comment does not have an @about-attribute to relate back to, since it has to relate back to a reply and not the document as a whole. Therefore it needs to have a slightly different graph stating what to relate to:

		class="comment comment-published clearfix">	

Here the @about-attribute with the value of "/node/2#comment-1-this" states that we want to reference to the comment with this path. With this in place, the @rev and @rel-attributes points back to the @about-url stating sioc:reply_of and @has_reply respectively as relations between the previous comment and the current one. Lastly, the @resource-attribute states the current node to be the "object" of the relations.

Making a distinction between logged in users and anonymous users

The semantics regarding the role of a user is important to express, since a logged in Drupal user is both considered an user AND a person, while an anonymous user should just be marked up as a person.

Logged in users
	<div class="submitted">
	    Submitted by
		<span rel="sioc:has_creator dc:creator">
			<span property="foaf:name" 
Anonymous users
	<div class="submitted">
	    Submitted by 
			rel="sioc:has_creator dc:creator">
				<a href="http://example.com/" 
					rel="nofollow foaf:homepage" 
					property="foaf:name">Somebody Anonymous
		</span> (not verified)

In the case of anonymous users, the only identificator we have, is the contact information in the case that this is mandatory. (How do we do this when this is not mandatory?). To represent the information of the anonymous user we could use the @typeof-attribute with a value of foaf:Person, and set an @about-attribute with the value set to the anonymous user's web page url to establish the subject of the following contact information. One then creates a child element and populate it with contact information using attribute values such as foaf:homepage and foaf:name

Back to the top

RDFa Glossary

A Compact URI (prefix:reference). A CURIE is a representation of a full URI. This URI is obtained by taking the currently in-scope mapping that is associated with prefix, and concatenating it with the reference. The resulting URI MUST be a syntactically valid IRI
Internationalized Resource Identifiers
A Uniform Resource Identifier Reference
A URI or safe_curie.
has_creator.png132.09 KB
has_creator_triple.png11.1 KB
title_triple.png5.98 KB

Semantic Web

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: