34

What are the conceptual differences between rdf:resource, rdf:about, and rdf:ID. I did some investigation but the difference between them are not clear for me yet. For example, whether rdf:ID is used when declaring a resource for the first time, rdf:resource is used for referencing an already existing resource, etc.

I would be glad if you provide some little examples.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
suat
  • 4,239
  • 3
  • 28
  • 51

2 Answers2

64

To be clear this is only about a particular way of writing rdf: namely RDF/XML. Other syntaxes don't feature these differences.

With that disclaimer out of the way:

What we're trying to do is write statements of the form:

subject predicate object

and in particular:

subjectURI predicate objectURI

So how do we introduce subject and object URIs in RDF/XML?

  1. rdf:about sets the subject URI of a statement, which may be absolute (http://example.com/) or resolved relative to the BASE of the document (e.g. /foo/bar, #frag). (Like href in html)
  2. rdf:resource sets the object URI of a statement, once again either absolute or relative.
  3. rdf:ID sets the subject URI, but it can only be within this document. An ID can also only be used once. Very like <a name="baz"> or id="baz" in html.

rdf:ID is discouraged since

  1. you can replace it with an rdf:about or rdf:resource with a fragment #baz and
  2. it can cause xml issues if you use the same id more than once.

That is, it's redundant and a potential source of errors.

In retrospect there typically only needs to be one attribute to specify a URI, since whether something is a subject or object is apparent from the RDF/XML syntax:

<ex:Foo ...> - subject
  <ex:prop ... /> - property then object
</ex:Foo>

<ex:Foo ...> - subject
  <ex:prop> - property
    <ex:Bar ... /> - subject (and implictly an object chaining from previous) 
...

(rule of thumb: odd lines rdf:about, even lines, rdf:resource)

and using both rdf:about and rdf:resource on an element is almost always an error (you're either in a subject position or object position).

tl;dr

Avoid rdf:ID. Use rdf:about and rdf:resource much like an href, the former for subject, the latter for objects.

Additional

Forgot to mention that rdf:ID can be used on a property element, but it does something you may find unexpected: it reifies the triple. Avoid rdf:ID.

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
user205512
  • 8,798
  • 29
  • 28
  • 1
    Just edited to fix some errors, and fudge a little. RDF/XML is a bit nasty, and I'd avoid it if you're new to RDF. Use a syntax like n-triples or turtle where the mapping to the RDF model is much simpler. You can always convert to RDF/XML using a tool like rapper. – user205512 Aug 19 '11 at 10:48
4

I would like to clarify a few of the excellent points in the provided answer, but only with respect to rdf:ID and rdf:about.

The tags are used to build a URI. If the full URI is not provided (such as rdf:ID="x"), then the generated URI is relative to the in-scope base URI usually derived from the document's location, but it can be specified with the xml:base attribute.

The point (mentioned above) is that rdf:about may be a fully qualified URI, so it is easy to just set it.

rdf:ID cannot be a fully qualified URI, but, you can still control that if you manually set the xml:base attribute.

The general rule of thumb for me, therefore, is to use rdf:about for a "globally known" identifier (when you want the URI to always be the same) and to use rdf:ID when describing a local resource whose URI is not cared about outside of the current document.

Andrew
  • 816
  • 7
  • 15