Visions of Aestia

16 Dec 2004

Refactoring to RDF, step 1

Filed under: Programming, PlanetRDF — JBowtie @ 12:52 pm

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:


John Smith






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.


John Smith






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.


John Smith






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.

6 Responses to “Refactoring to RDF, step 1”

  1. Dave Beckett Says:

    It should be rdf:ID. I suggest you use the W3C’s RDF validator
    or get a real rdf parser to check your examples.

  2. John C Barstow Says:

    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.

  3. Visions of Aestia » Refactoring to RDF, step 2 Says:

    […] iled under: Programming RDF — JBowtie @ 11:26 am You might want to review Part 1 before proceeding. Our document fragment last looked like this:

  4. Visions of Aestia » rdf:ID and relative URIs Says:

    […] 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 […]

  5. Ed Davies Says:

    According to section 2.14 of the syntax spec rdf:ID="name" is equivalent to rdf:ID="#name". Therefore customer#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.

  6. John C Barstow Says:

    Ed, that’s a good point. I’ll make a post on that subject. I probably should have used rdf:about.

Leave a Reply

Powered by WordPress