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"
Ā "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
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.
RDFa is icky compared to <link rel=”alternate” …> but does have the advantage of keeping everything together in one file. Except of the CSS, images, javascript etc… so I still fail to see the real gain in RDFa. Ah, well, ours not to ask WTF, our just to say “I told you so” in a few years time.
I’ve gone for the rather safer, but less funky approach of just serialising my relevant triples into an invisible structure at the top of the page. My first stab was all <div’s> but due to a quirk of the system I’m using (not EPrints in this case, but a PHP library + Javascript HTML editor), certain pages <div class=”RDFa”>…</div> block ended up inside a <p> and the validator got all huffy at me again. By the way, the class=”RDFa” was just to be tidy, it has no meaning in RDFa, but I used it to make it clear what this weird chunk was.
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.
You might also get asked to support GRDDL, which takes what you’ve described and adds a layer of XSLT into the mix so that even more formats can be supported from the single XHTML source.
It’s… novel.
Yes I might, and that’ll make even more of a hash of the underlying XHTML. It’s bad enough doing things like foo to get css effects to work the way I need.
This all sounds like academic wank to me. Unless it’s easy for people to pick up and run with, it’s doomed and wasted effort on my part (ie. I’ll try to avoid putting much effort in)
Of course, I seem to recall saying that wiki’s would never work, and I think Wendy once said that HTTP+HTML would never catch on. But I hope embedded semantics hacks like this die a death.