What Is RDF and How Does RDF/XML Syntax Work?
This article provides a concise guide to the Resource Description Framework (RDF) and its XML serialization format, RDF/XML. It covers the fundamental concepts of RDF as a metadata data model for the Semantic Web, explains the structure of RDF triples, and demonstrates how RDF statements are encoded and structured within standard XML syntax.
What is RDF?
The Resource Description Framework (RDF) is a standard data model developed by the World Wide Web Consortium (W3C) for representing information and relationships on the Web. Unlike traditional relational databases that organize data into tables, RDF models data as a directed, labeled graph.
The primary purpose of RDF is to facilitate data interchange and automated processing across different systems by giving data a machine-readable semantic meaning.
The RDF Triple
At the core of RDF is the “triple” concept. Every statement in RDF consists of three distinct components:
- Subject: The resource being identified or described, typically represented by an Internationalized Resource Identifier (IRI) or a Blank Node.
- Predicate: The specific property, trait, or relationship connecting the subject to the object, represented by an IRI.
- Object: The value of the property or the related resource. An object can be an IRI, a Blank Node, or a literal value (such as a string, integer, or date).
When multiple triples share subjects or objects, they interlink to form an RDF graph.
What is RDF/XML Serialization?
RDF is an abstract data model that can be written down (serialized) using several different concrete syntaxes, such as Turtle, N-Triples, JSON-LD, and RDF/XML.
RDF/XML is the original standard syntax for encoding RDF graphs using Extensible Markup Language (XML). It provides a way to represent graph data inside a hierarchical, tree-based XML document so that standard XML parsers and tools can process semantic metadata.
How RDF/XML Syntax Functions
RDF/XML uses standard XML elements, attributes, and namespaces to map XML nodes directly to RDF subjects, predicates, and objects.
1. Root Element and Namespaces
An RDF/XML document is enclosed in the <rdf:RDF>
root element. This element defines the XML namespaces used throughout
the document to avoid naming collisions and to abbreviate long IRIs into
compact prefixes.
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:schema="https://schema.org/">2.
Identifying the Subject (rdf:Description and
rdf:about)
The subject of a statement is declared using the
<rdf:Description> element. The rdf:about
attribute specifies the IRI of the resource being described.
<rdf:Description rdf:about="https://example.org/books/semantic-web-guide">
<!-- Predicates and Objects go here -->
</rdf:Description>3. Representing Predicates and Literal Objects
Child elements inside <rdf:Description> represent
the predicates. The text content inside these elements represents
literal objects.
<rdf:Description rdf:about="https://example.org/books/semantic-web-guide">
<dc:title>Semantic Web Guide</dc:title>
<dc:date>2024-01-15</dc:date>
</rdf:Description>- In this example:
- Subject:
https://example.org/books/semantic-web-guide - Predicate:
http://purl.org/dc/elements/1.1/title - Object:
"Semantic Web Guide"(Literal)
- Subject:
4. Representing
Resource Objects (rdf:resource)
When the object of a triple is another resource with an IRI (rather
than a literal value), the rdf:resource attribute is used
on the predicate element instead of enclosed text.
<rdf:Description rdf:about="https://example.org/books/semantic-web-guide">
<dc:creator rdf:resource="https://example.org/authors/jane-doe"/>
</rdf:Description>- This establishes a link between the book resource and the author resource.
5. Typed Nodes (Syntactic Shortcut)
To indicate that a subject belongs to a specific class (an
rdf:type relationship), RDF/XML allows the element name to
be replaced directly with the class name instead of using
<rdf:Description>.
Instead of:
<rdf:Description rdf:about="https://example.org/books/semantic-web-guide">
<rdf:type rdf:resource="https://schema.org/Book"/>
</rdf:Description>You can write:
<schema:Book rdf:about="https://example.org/books/semantic-web-guide">
<dc:title>Semantic Web Guide</dc:title>
</schema:Book>6. Datatypes and Languages
RDF/XML supports data typing and language tags on literal values: *
Datatypes: Defined using the rdf:datatype
attribute (e.g.,
rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"). *
Language Tags: Defined using the standard
xml:lang attribute (e.g., xml:lang="en").
Complete RDF/XML Example
Below is a complete, valid RDF/XML document that combines these concepts to describe a book, its title, publication year, and author relationship:
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:schema="https://schema.org/">
<schema:Book rdf:about="https://example.org/books/semantic-web-guide">
<dc:title xml:lang="en">Semantic Web Guide</dc:title>
<dc:creator rdf:resource="https://example.org/authors/jane-doe"/>
</schema:Book>
<schema:Person rdf:about="https://example.org/authors/jane-doe">
<schema:name>Jane Doe</schema:name>
</schema:Person>
</rdf:RDF>When parsed by an RDF processor, this XML structure resolves into four graph triples that unambiguously state the existence of a Book and a Person, their names, and the relationship between them.