RDF in XML

In preparation for Chapter 6, we need to look at how RDF is written in XML.

The Root Element

In all the examples in this book, I have given the RDF attributes a prefix of rdf:. This is not necessary in many RDF documents, but it is the way they appear in RSS 1.0. For the sake of clarity, we will leave them in here too. Therefore, for reasons we will discuss in Chapter 6, the root element of an RDF document is:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
. . .
</rdf:RDF>

As we will see in Chapter 6, the root element can also contain the URIs of additional RDF vocabularies. In the following examples, we will use elements from the RSS 1.0 vocabulary.

<element rdf:about="URI OF ELEMENT">

The rdf:about attribute defines the URI for the element that contains it. Remember, it is like the subject in a sentence—everything else refers to it. For example:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns="http://purl.org/rss/1.0/"
>
<channel rdf:about="http://www.example.org/">
. . .
</channel>
</rdf:RDF>

means the channel resource is identified by the URI http://www.example.org/. Or, more to the point, everything within the channel element is referred to by http://www.example.org.

The contents of the element then describe the object referred to by the URI:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
         xmlns="http://purl.org/rss/1.0/" >
<channel rdf:about="http://www.example.org">
<title>Sausages are tasty for breakfast</title> ...

Get Content Syndication with RSS now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.