The RDF XML Schema


The Ernest Hemingway example that I put together in the visual designer of Altova's SemanticWorks tool generated the bit of XML shown in Listing 24-1.

Listing 24-1: An example RDF document-Hemingway.rdf

image from book
      <?xml version="1.0"?>      <rdf:RDF xmlns:ex="http://www.example.org/"        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">            <rdf:Description rdf:about="http://www.example.org/Ernest_Hemingway">            <ex:wrote_a_book>               <ex:book rdf:about="http://www.example.org/The_Sun_Also_Rises"/>            </ex:wrote_a_book>            <ex:wrote_a_book>               <ex:book rdf:about="http://www.example.org/For_Whom_the_Bell_Tolls"/>            </ex:wrote_a_book>            <ex:had_a_grand-daughter>               <ex:person rdf:about="http://www.example.org/Mariel_Hemingway"/>            </ex:had_a_grand-daughter>            </rdf:Description>            <rdf:Description rdf:about="http://www.example.org/Mariel_Hemingway">            <ex:starred_in_movie>               <ex:movie rdf:about="http://www.example.org/Manhattan"/>            </ex:starred_in_movie>          </rdf:Description>      </rdf:RDF> 
image from book

As you can see, the RDF document is a normal XML document. It follows the XML syntax and begins with an <?xml> element just as other XML document would. The root element, <rdf> starts by defining a couple of namespaces. The two namespaces include

  • q http://www.w3.org/1999/02/22-rdf-syntax-ns#

  • q http://www.example.org

The first item in the list is the namespace of the RDF schema, which should be included by default in all your RDF documents. The second namespace is your own. In this case, it is xmlns:ex=“http://www.example.org/” so it can be used as a custom prefix throughout the document.

Each subject in the document is then defined using an <rdf:Description> element. For instance, the description of Mariel_Hemingway in the document includes the following code:

      <rdf:Description rdf:about="http://www.example.org/Mariel_Hemingway">         <ex:starred_in_movie>            <ex:movie rdf:about="http://www.example.org/Manhattan"/>         </ex:starred_in_movie>      </rdf:Description> 

If you study this bit of code and how it relates to other elements, you can see that the URI is indeed the identifier of the resource. Using the <rdf:Description> element, you select the rdf:about attribute to assign the URI to the item. In this case, it is http://www.example.org/Mariel_Hemingway.

Now that the subject is in place, the next step is to assign the predicate. You use the custom prefix and assign a defining element, which is the predicate itself.

      <ex:starred_in_movie>      </ex:starred_in_movie> 

The predicate is the <ex:starred_in_movie> element. This means that the action is applied to anything assigned within this element. This is now the object of the statement.

      <ex:starred_in_movie>         <ex:movie rdf:about="http://www.example.org/Manhattan"/>      </ex:starred_in_movie> 

This predicate is acting upon the <ex:movie> element. Again, this element uses the rdf:about attribute to assign the URI of the resource. The URI of the movie Manhattan is utilized for the <ex:movie> element.

After adding this complete <rdf:Description> element, you have a full statement. Each of the items of the statement is presented here:

  • q Subject-http://www.example.org/Mariel_Hemingway

  • q Predicate-<ex:starred_in_movie></ex:starred_in_movie>

  • q Object-http://www.example.org/Manhattan

You can have more than one predicate per statement as you see here:

      <rdf:Description rdf:about="http://www.example.org/Ernest_Hemingway">         <ex:wrote_a_book>            <ex:book rdf:about="http://www.example.org/The_Sun_Also_Rises"/>         </ex:wrote_a_book>         <ex:wrote_a_book>            <ex:book rdf:about="http://www.example.org/For_Whom_the_Bell_Tolls"/>         </ex:wrote_a_book>         <ex:had_a_grand-daughter>            <ex:person rdf:about="http://www.example.org/Mariel_Hemingway"/>         </ex:had_a_grand-daughter>      </rdf:Description> 

In this case, three predicates are used:

  • q <ex:wrote_a_book> associated to the object The_Sun_Also_Rises

  • q <ex:wrote_a_book> associated to the object For_Whom_the_Bell_Tolls

  • q <ex:had_a_grand-daughter> associated to the object Mariel_Hemingway

One of the objects (Mariel_Hemingway) is even further defined with its own statement. This is how two statements are related to each other.

From this XML document, you see that you can extend the metadata definition and incorporate as many additional subjects, predicates, and objects as you wish. The order in which they appear in the document is not important because the document is webbed together through the use of the URIs utilized in the statements.




Professional XML
Professional XML (Programmer to Programmer)
ISBN: 0471777773
EAN: 2147483647
Year: 2004
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net