RDFa is a way of embedding RDF data into an XHTML document. I remain unconvinced that this is a great idea, but some of the cool kids seem to be doing it, and I’ve been asked to add it to some of our sites & tools so I’ve been looking into it.
RDFa is a little bit like a microformat. Those are ways of expressing semantic content in XHTML by use of sneaky class=”…” attributes. The first way in which they differ is that RDFa is far more versatile, as many data formats have an RDF expression already and only one tool is required, rather than one-per-microformat. The second difference is that it uses new attributes that are not in XHTML. This means your XHTML document containing RDFa is not valid XHTML. This kind of freaked my out, until I discovered that all I had to do was change my doctype to:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
At which point the W3C validator – http://validator.w3.org/ – liked me again.
RDFa is intended to cleverly annotate your existing document structure to describe semantic relationships. While this is cool in theory, in practice it’s a pain in the arse, like microformats. I would only advocate outputting it from tools, nobody should try and write this stuff right into their pages. It can be useful for things like blog tools, and I’ll consider adding it to EPrints, but I am very concerned that I don’t want people modifying the page layout to have semantic implications because most people don’t have time to care about this stuff. They don’t mind supporting linked data and the semantic web so long as they have to do no extra work and learn no new skills. If we don’t make it happen automatically we won’t get to the critical mass where tools become common and useful and it becomes worth non-advocates putting the effort into creating good linked data. Until then we must make it happen without bothering people.
I solved the validation annoyance by using <span> instead of <div>. Span’s are welcomed pretty much everywhere.
I then ran into another problem. On a slow connection the .css file didn’t load at once and all by text appeared as a big ugly pile at the top of the page, so I’ve added an explicit style=”display:none” rather than do it in .css files as I normally would.
The final result:
<span style='display:none' class='RDFa' xmlns:foaf='http://xmlns.com/foaf/0.1/' xmlns:owl='http://www.w3.org/2002/07/owl#' > <span typeof="foaf:Person" about='http://example.org/person/7'> <span rel='foaf:homepage' resource='http://users.ecs.soton.ac.uk/people/cjg'></span> <span property='foaf:family_name'>Gutteridge</span> <span property='foaf:givenname'>Christopher</span> <span property='foaf:name'>Christopher Gutteridge</span> <span rel='owl:sameAs' resource='http://id.ecs.soton.ac.uk/person/1248'></span> </span> <span typeof="foaf:Organization" about='http://example.org/#org'> <span rel='foaf:member' resource='http://example.org/person/7'></span> </span> </span>
There’s an inverse “rel” attribute, but I couldn’t be arsed to use it as I just copy-and-hacked my triples to RDF/XML function.
I’m not proud of this, but figured the above example will save people time on an annoying but fashionable format. I hope it dies a death, but for now I’ll endeavor to support it.
In the meantime, don’t forget to change your DOCTYPE.