Refactoring to RDF, step 1
OK, let’s say you’ve decided to take the plunge and switch from plain XML to the distributed kind you get with RDF. How are you going to get there?
Step 0: Make sure your XML parser understands namespaces. You’re going to be needing them.
The first refactoring should be pretty easy. You need to replace any existing ID values in your XML with RDF-specific IDs.
Let’s look at an example snippet:
Probably this XML comes from a database somewhere. Doesn’t really matter. The thing to recognise here is that the “id” attribute is actually being used as both an anchor and a reference.
Pass one, we replace the anchors.
Remember, RDF just uses the ID value as a unique key. It doesn’t have to point to a real document.
In pass two, we replace the references.
We also have to update any existing XML parsing we do to use the new attribute values instead of the old ones, but that should be straightfoward.
UPDATE: Fixed broken example tags. Yeesh - and the characters WordPress ate.
UPDATE (27-Dec-2004): Fixed embarrassing typo in response to Dave’s comment below.
December 24th, 2004 at 12:23 am
It should be rdf:ID. I suggest you use the W3C’s RDF validator
or get a real rdf parser to check your examples.
December 27th, 2004 at 8:39 pm
How embarrassing! In my defense, my blogging software ate half the tags when I first posted. But you’re right, I really should be validating all my examples instead of rattling them off my head.
I’ve fixed the post to avoid misleading people in the future.
January 16th, 2005 at 10:26 pm
[…] iled under: Programming RDF — JBowtie @ 11:26 am You might want to review Part 1 before proceeding. Our document fragment last looked like this:
January 18th, 2005 at 10:43 pm
[…] ative URIs, but rdf:ID does not. Specifically, as Ed Davies points out in his comment to Refactoring to RDF, step 1, a relative rdf:ID is always interpreted as an anchor within the curren […]
January 19th, 2005 at 12:18 am
According to section 2.14 of the syntax spec
rdf:ID="name"
is equivalent tordf:ID="#name"
. Thereforecustomer#12
will be treated as#customer#12
which is not what you mean, I think. In fact, I’m not sure if it is even legal at all.January 19th, 2005 at 10:28 am
Ed, that’s a good point. I’ll make a post on that subject. I probably should have used rdf:about.