[ Team LiB ] |
3.3 URI ReferencesAll predicates within RDF/XML are given as URIs, and most resources—other than those that are treated as blank nodes—are also given URIs. A basic grounding of URIs was given in Chapter 2, but this section takes a look at how URIs are used within the RDF/XML syntax. 3.3.1 Resolving Relative URIs and xml:baseNot all URI references in a document are full URIs. It's not uncommon for relative URI references to be given, which then need to be resolved to a base URI location. In the previous examples, the full resource URI is given within the rdf:about attribute. Instead of using the full URI, the example could be a relative URI reference, which resolves to the base document concatenated with the relative URI reference. In the following, the relative URI reference "#somevalue.htm": <rdf:Description rdf:about="#somevalue"> then becomes http://burningbird.net/articles/somedoc.htm#somevalue if the containing document is http://burningbird.net/articles/somedoc.htm. To resolve correctly, the relative URI reference must be given with the format of pound sign (#) followed by the reference ("#somevalue"). Normally, when a full URI is not provided for a specific resource, the owning document's URL is considered the base document for forming full URIs given relative URI references. So if the document is http://burningbird.net/somedoc.htm, the URI base is considered to be this document, and changes of the document name or URL change the URI for the resource. With xml:base, you can specify a base document that's used to generate full URIs when given relative URI references, regardless of the URL of the owning document. This means that your URIs can be consistent regardless of document renaming and movement. The xml:base attribute is added to the RDF/XML document, usually in the same element tag where you list your namespaces (though it can be placed anywhere). Redefining Example 3-6 with xml:base and using a relative URI reference would give you the RDF/XML shown in Example 3-10. Example 3-10. Using xml:base to define the base document for relative URI references<?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="monsters3.htm"> <pstcn:author rdf:parseType="Literal" /> </rdf:Description> </rdf:RDF> The URI for the article, given as relative "monsters3.htm", is correctly expanded to the proper full URI of http://burningbird.net/articles/monsters3.htm. 3.3.2 Resolving References with rdf:IDIn the previous example, the rdf:about attribute was used to provide the URI reference. Other ways of providing a URI for a resource are to use the rdf:resource, rdf:ID, or rdf:bagID attributes. The rdf:bagID attribute is discussed in the next chapter, but we'll take a quick look at rdf:ID and rdf:resource. Unlike the rdf:about attribute, which refers to an existing resource, rdf:ID generates a URI by concatenating the URI of the enclosing document (or the one provided by xml:base) to the identifier given, preceded by the relative URI # symbol. Rewriting Example 3-5 to use rdf:ID for the second resource results in the RDF/XML shown in Example 3-11. Example 3-11. Using rdf:ID to provide identifier for resource<?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/"> <rdf:Description rdf:ID="monsters3.htm"> <pstcn:author>Shelley Powers</pstcn:author> <pstcn:title>Architeuthis Dux</pstcn:title> <pstcn:series> <rdf:Description rdf:ID="monsters.htm"> <pstcn:seriesTitle>A Tale of Two Monsters </pstcn:seriesTitle> </rdf:Description> </pstcn:series> <pstcn:contains>Physical description of giant squids</pstcn:contains> <pstcn:alsoContains>Tale of the Legendary Kraken </pstcn:alsoContains> </rdf:Description> </rdf:RDF> The generated RDF graph would show a resource giving the URI of the enclosing document, a pound sign (#), and the ID. In this case, if the enclosing document was at http://burningbird.net/index.htm, it would show a URI of http://burningbird.net/index.htm#monsters3.htm. This same effect can be given with the rdf:about by using a URI of "#monsters". As you can see, the URI of the resolved relative URI reference doesn't match that given previously: http://burningbird.net/index.htm#monsters3.htm does not match http://burningbird.net/articles/monsters3.htm. Based on this, I never use rdf:ID for actual resources; I tend to use it when I'm defining a resource that usually wouldn't have an actual URI but would have one primarily to support the required node-arc-node-arc-node nature of RDF/XML. For example, the pstcn:series attribute given to the http://burningbird.net/articles/monsters.htm URI really doesn't exist—it's a way of showing a relationship between the article and a particular series, which has properties in its own right though it does not actually exist as a single object. Instead of using the full URI, what I could have done is use ID, as shown in Example 3-12. Example 3-12. Using xml:base to identify the base document for all relative URI references<?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="monsters3.htm"> <pstcn:author>Shelley Powers</pstcn:author> <pstcn:title>Architeuthis Dux</pstcn:title> <pstcn:series> <rdf:Description rdf:ID="monsters"> <pstcn:seriesTitle>A Tale of Two Monsters </pstcn:seriesTitle> </rdf:Description> </pstcn:series> <pstcn:contains>Physical description of giant squids</pstcn:contains> <pstcn:alsoContains>Tale of the Legendary Kraken </pstcn:alsoContains> </rdf:Description> </rdf:RDF> The relative URI then resolves to http://burningbird.net/articles/#monsters, forming a representation of the URI as an identifier rather than an actual URL (a misunderstanding that can occur with URI references, since not all URIs are URLs). The rdf:ID is considered to have reified the statement (i.e., formally identified the statement within the model). The discussion about reification is continued in Chapter 4. |
[ Team LiB ] |