RDF Syntax

RDF documents are made of RDF statements that describe resources. Each statement has three parts, so it's called a triple. Here are the three parts of an RDF statement:

  • Resource. Resources are typically Web documents that you point to with a URI.

  • Named property. Such a property is a specific characteristic or attribute of the resource, such as the resource's creator.

  • Property value. The value of the property is the property's content. For example, the value of the <Creator> property is usually the name of the resource's creator.

An RDF statement, then, is made up of a resource, a named property, and a property value. In RDF, you name these three parts like this:

  • The resource is called the subject of the statement.

  • The named property is called the predicate of the statement.

  • The property value is called the object of the statement.

Here's a simple example RDF document:

<?xml version="1.0" ?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description about="http://www.starpowder.com/planets.html">
        <Creator>Nicolas Copernicus</Creator>
    </rdf:Description>

In this case, the subject is the document "http://www.starpowder.com/planets.html", the predicate is the named property Creator, and the object is the name of the document's creator, Nicolas Copernicus. To understand RDF, I'm going to take this document apart piece by piece now.

The RDF Root Element

Because RDF documents are also XML documents, they start with the <?xml?> declaration. These documents also must have a specific root element, <RDF>, which encloses the rest of the document. Because the namespace you use with RDF is usually given the prefix rdf, you often specify the <RDF> element as <rdf:RDF>, like this:

<?xml version="1.0" ?>
<rdf:RDF
        .
        .
        .
</rdf:RDF>

Also, note that RDF documents must use the RDF namespace.

The RDF Namespace

The official, W3C-defined, RDF namespace is "http://www.w3.org/1999/02/22-rdf-syntax-ns#" (the # on the end, which may look pretty funny, is not an error; it's there to help applications create valid XPointers). All RDF documents must use this namespace. The conventional prefix for this namespace is rdf, so I'll declare that prefix like this:

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

The RDF Description Element

Each resource that you want to describe in RDF gets its own <rdf:Description> element. This element has several attributes:

AttributeDescription
aboutLets you specify what resource the element describes
aboutEachLets you make statements about each of the element's children
aboutEachPrefixLets you select RDF container items by prefix
bagIDSpecifies the ID of an associated bag container
IDLets you give the element an ID value
typeSpecifies the description's type

In fact, you can also convert the properties you list in the <rdf:Description> element into attributes, as we'll see when we take a look at the RDF abbreviated syntax.

In our example, the resource being described is the document "http://www.starpowder.com/planets.html", so I assign that URI to the about attribute of the <rdf:Description> element:

<?xml version="1.0" ?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description about="http://www.starpowder.com/planets.html">
    .
    .
    .
    </rdf:Description>
</rdf:RDF>

In other words, you use the about attribute to specify the statement's subject.

To actually say something about the resource, you use property elements.

RDF Property Elements

Inside the <rdf:Description> element, you store the actual elements that describe the subject. In the current example, the predicate is the Creator property, which specifies the document's author, and the object is the name of the author, Nicolas Copernicus:

<?xml version="1.0" ?>
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description about="http://www.starpowder.com/planets.html">
        <Creator>Nicolas Copernicus</Creator>
    </rdf:Description>
</rdf:RDF>

The Creator property is not built into the RDF specification—in fact, no properties are. It's up to you to create the named properties you want to use to describe a resource. In fact, a number of property sets, called RDF content description models, already are available. That's useful because they provide some agreement on property names—which means that applications such as Web search engines can make some sense out of the properties you use. The most popular and well-supported of these RDF content description models is the Dublin Core.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.2