[ Team LiB ] Previous Section Next Section

3.2 RDF Blank Nodes

It would be easy to extrapolate a lot of meaning about blank nodes but, bottom line, a blank node represents a resource that isn't currently identified. As with the infamous null value from the relational data model, there could be two reasons why the identifying URI is absent: either the value will never exist (isn't meaningful) or the value could exist but doesn't at the moment (currently missing).

Most commonly, a blank node—known as a bnode, or occasionally anonymous node—is used when a resource URI isn't meaningful. An example of this could be a representation of a specific individual (since most of us don't think of humans with URIs).

In RDF/XML, a blank node is represented by an oval (it is a resource), with either no value in the oval or a computer-generated identifier. The RDF/XML Validator generates an identifier, which it uses within the blank node to distinguish it from other blank nodes within the graph. Most tools generate an identifier for blank nodes to differentiate them.

In Example 3-8, bio attributes are grouped within an enclosing PostCon bio resource. Since the bio doesn't have its own URI, a blank node represents it within the model.

Example 3-8. Blank node within RDF model
<?xml version="1.0"?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:pstcn="http://burningbird.net/postcon/elements/1.0/"
  xml:base="http://burningbird.net/articles/">

  <rdf:Description rdf:about="monsters1.htm">
     <pstcn:bio>
       <rdf:Description>
     		<pstcn:title>Tale of Two Monsters: Legends</pstcn:title>
            <pstcn:description>
               Part 1 of four-part series on cryptozoology, legends, 
               Nessie the Loch Ness Monster and the giant squid.
            </pstcn:description>
     		<pstcn:created>1999-08-01T00:00:00-06:00</pstcn:created>
     		<pstcn:creator>Shelley Powers</pstcn:creator>
  	 </rdf:Description>
     </pstcn:bio>
   </rdf:Description>
</rdf:RDF>

Running this example through the RDF Validator gives the directed graph shown in Figure 3-6 (modified to fit within the page).

Figure 3-6. Directed graph demonstrating blank node
figs/prdf_0306.gif

As you can see in the graph, the RDF Validator has generated a node identifier for the blank node, genid:403. This identifier has no meaning other than being a way to differentiate this blank node from other blank nodes, within the graph and within the generated N-Triples.

Example 3-8 also uses xml:base to establish a base URI for the other URIs in the document, avoiding a lot of repetition. This technique is described in more detail in Section 3.3.

Instead of letting the tools provide a blank node identifier, you can provide one yourself. This is particularly useful if you want to reference a resource that's not nested within the outlying element but occurs elsewhere in the page as a separate RDF/XML triple. The rdf:nodeID is used to provide a specific identifier, as demonstrated in Example 3-9, when the embedded bio is pulled out into a separate triple. The rdf:nodeID attribute is used within the predicate of the original triple, as well as within the description of the newly created triple, as noted in bold type.

Example 3-9. Using rdf:nodeID to identify a unique blank node
<?xml version="1.0"?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:pstcn="http://burningbird.net/postcon/elements/1.0/"
  xml:base="http://burningbird.net/articles/">

  <rdf:Description rdf:about="monsters1.htm">
     <pstcn:bio rdf:nodeID="monsters1">
     </pstcn:bio>
   </rdf:Description>

   <rdf:Description rdf:nodeID="monsters1">
	<pstcn:title>Tale of Two Monsters: Legends</pstcn:title>
      <pstcn:description>
            Part 1 of four-part series on cryptozoology, legends, 
            Nessie the Loch Ness Monster and the giant squid.
      </pstcn:description>
	<pstcn:created>1999-08-01T00:00:00-06:00</pstcn:created>
	<pstcn:creator>Shelley Powers</pstcn:creator>
  </rdf:Description>
</rdf:RDF>

The rdf:nodeID is unique to the document but not necessarily to all RDF/XML documents. When multiple RDF models are combined, the tools used could redefine the identifier in order to ensure that it is unique. The rdf:nodeID is not a way to provide a global identifier for a resource in order to process it mechanically when multiple models are combined. If you need this type of functionality, you're going to want to give the resource a formal URI, even if it is only a placeholder URI until a proper one can be defined.

As noted in the RDF Syntax Specification document, nodeID is unique to RDF/XML only, and does not have any representation within the RDF abstract model. It's a tool to help people work with RDF/XML; not part of the RDF model.

    [ Team LiB ] Previous Section Next Section