Sep 27 2005
The Sixteen Faces of Eve
My goal in this posting, prompted by some email discussions on constrained profiles of RDF/XML, is to take three simple triples and see how many ways there were of serialising them as RDF/XML. I chose not to consider order of the elements to be significant - I may be mean but I’m not without a heart.
The triples I chose were trivial. In prose they are: “there is something that is a person, with a name of Eve and a homepage of http://example.org/~eve”. In Turtle/NTriples/N3:
_:eve rdf:type foaf:Person .
_:eve foaf:name "Eve" .
_:eve foaf:homepage <http://example.org/~eve>.
When I started this posting I thought I could squeeze out seven RDF/XML serializations of the same three triples, so I had a clever name for the post all worked out. When I actually came to serialize the triples I came up with sixteen variations! It rather spoilt the joke but it sort of hammers home the point I’m trying to make.
Here’s a challenge for a talented XPather: write an XPath that selects the homepage of the person with name “Eve”. It must work with all sixteen of these serialisations.
Remember, all of these XML documents parse to the same three triples above. My maths is too rusty to work out how many serialisations there are of 4, 5, 6 or more triples let alone the few hundred that comprise my FOAF file.
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person>
<foaf:name>Eve</foaf:name>
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</foaf:Person>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description>
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<foaf:name>Eve</foaf:name>
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person foaf:name="Eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</foaf:Person>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description foaf:name="Eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
</foaf:Person>
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:nodeID="eve" foaf:name="Eve" />
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<foaf:name>Eve</foaf:name>
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve" foaf:name="Eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
</rdf:Description>
<foaf:Person rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</foaf:Person>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
</rdf:Description>
<foaf:Person rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</foaf:Person>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve" foaf:name="Eve" />
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
</rdf:Description>
<rdf:Description rdf:nodeID="eve" foaf:name="Eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve">
<foaf:name>Eve</foaf:name>
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
</rdf:Description>
</rdf:RDF>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:nodeID="eve" foaf:name="Eve" />
<rdf:Description rdf:nodeID="eve">
<foaf:homepage rdf:resource="http://example.org/~eve"/>
</rdf:Description>
<rdf:Description rdf:nodeID="eve">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
</rdf:Description>
</rdf:RDF>
14 Responses to “The Sixteen Faces of Eve”

Heh, and couldn’t you write face 1-4 with namespaces declared in the inner tag and then drop the outer rdf:RDF?
That’s just cruel.
So what? There are several representations in Turtle for that graph as well (besides the one you indicated). Just because you can dig a trench with a spoon doesn’t mean it is a good idea (unless you are escaping from a prision).
Sure, but serializing as XML sort of suggests that you can use XML tools to process it. I’ve said before that it was a mistake ever to endorse an XML serialization of RDF, we should have had Turtle years ago.
You missed another variation: rdf:type can be an attribute. I think that doubles Eve’s faces.
I don’t think so, attributes can only take literal values.
I don’t see much wrong with the general ideas behind RDF/XML except that it is the only official format (although there are lots of flaws with the details). The idea behind RDF/XML is not that you use XML tools to read RDF, but that you use RDF tools to read XML. I.E. You mark up an existing XML document with RDF/XML attributes indicating its semantic structure (as opposed to the logical structure).
P.S. Re: 6. rdf:type is an exception for that rule, in that it is allowed as an attribute but still points to a URIRef and not a plain literal.
Hey I never knew that you could use rdf:type as an attribute in that way, but it’s legal. That’s another 10 variations on top of the 4 suggested by Ben. So, we’re up to 32 different ways to write 3 triples in RDF/XML
RDF/XML Sucks x 16 32
Caution. Rant ahead… I’ve always thought that the XML serialization of RDF is pretty much garbage. Sorry, had to say…
I’ll take you up on your XPath challenge. I think (he says hopefully) that the following should work:
//*[ ( .//foaf:name | .//@foaf:name ) = "Eve" ]//foaf:homepage/@rdf:resource
This assumes that the top-level context is a single document containing all 16 variations.
Good try Howard. I read that XPath as:
Select the rdf:resource attribute of the foaf:homepage element that is a descendant of an element which has either a foaf:name child element or a foaf:name attribute with the value of “Eve”
I don’t think that covers the faces where there foaf:name and foaf:homepage are children of different elements e.g. face 5
What I’ve got *should* work for the case where foaf:name or @foaf:name and foaf:homepage are descendants (not necessarily direct children) of different elements. The key is lots of “//” descendant specifiers to indicate that *somewhere* back up the hierarchy there’s a common element for both end points (name and homepage). When I have some time later on I’ll try this on face 5 just to make sure …
Respectfully; asking what’s the XPath is the wrong question. It’s dealing with symptoms.
Jimmy: the “So what” is that RDF/XML is like a box of chocolates; you never know what you’re gonna get.I know of no systems that are end to end model driven; you always have to deal with serializations, mappings, validation, form filling, presentation. The XML syntax sufficiently screws up the economic proposition of RDF that it makes sense to look at alternatives - a case of snatching defeat from the jaws of victory. It’s a nutso situation.