XML RDF
RDF Document Example
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:si="https://www.globaltuts.com/rdf/">
<rdf:Description rdf:about="https://www.globaltuts.com">
<si:title>globaltuts</si:title>
<si:author>Jan Egil Refsnes</si:author>
</rdf:Description>
</rdf:RDF>
What is RDF?
- RDF stands for Resource Description Framework
- RDF is a framework for describing resources on the web
- RDF is designed to be read and understood by computers
- RDF is not designed for being displayed to people
- RDF is written in XML
- RDF is a part of the W3C's Semantic Web Activity
- RDF is a W3C Recommendation from 10. February 2004
RDF - Examples of Use
- Describing properties for shopping items, such as price and availability
- Describing time schedules for web events
- Describing information about web pages (content, author, created and modified date)
- Describing content and rating for web pictures
- Describing content for search engines
- Describing electronic libraries
RDF is Designed to be Read by Computers
RDF was designed to provide a common way to describe information so it can be read and understood by computer applications.
RDF descriptions are not designed to be displayed on the web.
RDF is Written in XML
RDF documents are written in XML. The XML language used by RDF is called RDF/XML.
By using XML, RDF information can easily be exchanged between different types of computers using different types of operating systems and application languages.
RDF and "The Semantic Web"
The RDF language is a part of the W3C's Semantic Web Activity. W3C's "Semantic Web Vision" is a future where:
- Web information has exact meaning
- Web information can be understood and processed by computers
- Computers can integrate information from the web
RDF uses Web identifiers (URIs) to identify resources.
RDF describes resources with properties and property values.
RDF Resource, Property, and Property Value
RDF identifies things using Web identifiers (URIs), and describes resources with properties and property values.
Explanation of Resource, Property, and Property value:
- A Resource is anything that can have a URI, such as "https://www.globaltuts.com/rdf"
- A Property is a Resource that has a name, such as "author" or "homepage"
- A Property value is the value of a Property, such as "Jan Egil Refsnes" or "https://www.globaltuts.com" (note that a property value can be another resource)
The following RDF document could describe the resource "https://www.globaltuts.com/rdf":
<?xml version="1.0"?>
<RDF>
<Description about="https://www.globaltuts.com/rdf">
<author>Jan Egil Refsnes</author>
<homepage>https://www.globaltuts.com</homepage>
</Description>
</RDF>
The example above is simplified. Namespaces are omitted.
RDF Statements
The combination of a Resource, a Property, and a Property value forms a Statement (known as the subject, predicate and object of a Statement).
Let's look at some example statements to get a better understanding:
Statement: "The author of https://www.globaltuts.com/rdf is Jan Egil Refsnes".
- The subject of the statement above is: https://www.globaltuts.com/rdf
- The predicate is: author
- The object is: Jan Egil Refsnes
Statement: "The homepage of https://www.globaltuts.com/rdf is https://www.globaltuts.com".
- The subject of the statement above is: https://www.globaltuts.com/rdf
- The predicate is: homepage
- The object is: https://www.globaltuts.com
RDF Example
Here are two records from a CD-list:
| Title | Artist | Country | Company | Price | Year |
|---|---|---|---|---|---|
| Empire Burlesque | Bob Dylan | USA | Columbia | 10.90 | 1985 |
| Hide your heart | Bonnie Tyler | UK | CBS Records | 9.90 | 1988 |
Below is a few lines from an RDF document:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist>Bob Dylan</cd:artist>
<cd:country>USA</cd:country>
<cd:company>Columbia</cd:company>
<cd:price>10.90</cd:price>
<cd:year>1985</cd:year>
</rdf:Description>
<rdf:Description
rdf:about="http://www.recshop.fake/cd/Hide your heart">
<cd:artist>Bonnie Tyler</cd:artist>
<cd:country>UK</cd:country>
<cd:company>CBS Records</cd:company>
<cd:price>9.90</cd:price>
<cd:year>1988</cd:year>
</rdf:Description>
.
.
.
</rdf:RDF>
The first line of the RDF document is the XML declaration. The XML declaration is followed by the root element of RDF documents: <rdf:RDF>.
The xmlns:rdf namespace, specifies that elements with the rdf prefix are from the namespace "http://www.w3.org/1999/02/22-rdf-syntax-ns#".
The xmlns:cd namespace, specifies that elements with the cd prefix are from the namespace "http://www.recshop.fake/cd#".
The <rdf:Description> element contains the description of the resource identified by the rdf:about attribute.
The elements: <cd:artist>, <cd:country>, <cd:company>, etc. are properties of the resource.
RDF Online Validator
W3C's RDF Validation Service is useful when learning RDF. Here you can experiment with RDF files.
The online RDF Validator parses your RDF document, checks your syntax, and generates tabular and graphical views of your RDF document.
Copy and paste the example below into W3C's RDF validator:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:si="https://www.globaltuts.com/rdf/">
<rdf:Description rdf:about="https://www.globaltuts.com">
<si:title>globaltuts.com</si:title>
<si:author>Jan Egil Refsnes</si:author>
</rdf:Description>
</rdf:RDF>
When you parse the example above, the result will look something like this.
RDF Elements
The main elements of RDF are the root element, <RDF>, and the <Description> element, which identifies a resource.