4.2 Collections

Unlike a container, a collection is considered to be a finite grouping of items, with a given terminator. Within RDF/XML, a collection is defined through the use of rdf:parseType="Collection" and through listing the collected resources within the other collection block.

The use of Collection within RDF/XML is fairly straightforward and uncomplicated. Example 4-6 demonstrates how easy it is to gather together like items into one collection, just through the use of the Collection rdf:parseType.

Example 4-6. RDF/XML Document containing Collection with three items
<?xml version="1.0"?>
  <rdf:Description rdf:about="http://dynamicearth.com/earthstars/contest.htm">
   <pstcn:menu rdf:parseType="Collection">
      <rdf:Description rdf:about="http://burningbird.net/articles.htm" />
      <rdf:Description rdf:about="http://burningbird.net/dynatech.htm" />
      <rdf:Description rdf:about="http://burningbird.net/interact.htm" />


The extraordinary thing about Collection is the resulting RDF directed graph. One could be amazed at how the simple little addition of an rdf:parseType="Collection" could result in the rather complex model that's generated. Figure 4-3 shows what would result from this type of RDF/XML construct.

Figure 4-3. Generated RDF directed graph of a collection

As the graph demonstrates, a collection is a list (with rdf:type of rdf:List), and each node on the list has an associated predicate of type (List) as well as the first value in the list, given by the predicate rdf:first. Additionally, there is a relationship between the nodes, with an associated rdf:predicate of rdf:rest. The list is then terminated with a node, whose value is rdf:nil.

Traversing a collection becomes a matter of finding the start and then accessing the rdf:next predicate for that node and finding the associated resource attached to it, which then points to the value associated with it, and so on.

As complex as this structure is, though, there are still loopholes in the semantics associated with it. For instance, one could have multiple instances of rdf:first within a document; however, it would require a deliberate act to create this condition, which is unlikely to happen. Again, the RDF specification enforces only some basic understanding about lists, such as (as previously mentioned) each consists of a finite number of items with a terminator (though the terminator itself could be left off). Based on this, my recommendation is that you use the RDF collection as sparingly as you would use the RDF Container?use only when no other construct matches your specific needs, and use it specifically as the specification intended it to be used. If you're unsure about the intent, then don't use it.

Now that we've had a chance to look at the various grouping constructs of RDF?and to understand the associated dangers associated with them?it's time to look at another RDF construct that's caused even more controversy and confusion: reification.