RDF File Documentation


Summary

An .rdf file holds data in the W3C’s Resource Description Framework, the graph model behind the semantic web, usually written as RDF/XML text. It describes things as subject-predicate-object “triples”: ontologies, vocabularies, metadata and knowledge graphs. Its MIME type is application/rdf+xml. Being XML text, you can read it in any editor, but to work with it use an RDF tool such as Protege or a library like Apache Jena to query it with SPARQL and convert it to Turtle or JSON-LD.

Technical details

FeatureValue
Full nameResource Description Framework Document (RDF/XML)
File extension.rdf
MIME typeapplication/rdf+xml
Format typeText / XML: an RDF graph serialized as RDF/XML
DeveloperW3C
IntroducedRDF 1.0 Recommendation 1999; RDF 1.1 in 2014
Data modelDirected graph of subject-predicate-object triples
Character encodingUsually UTF-8 (XML text)
Root element<rdf:RDF xmlns:rdf="…">
Magic numberNone (text); typically starts <?xml version="1.0"…
Open standardYes (W3C Recommendation)
Other serializationsTurtle .ttl, N-Triples .nt, JSON-LD .jsonld, N3 .n3
Query languageSPARQL
Built on / usesIRIs, XML namespaces, XSD datatypes
Common vocabulariesOWL, SKOS, FOAF, Dublin Core, RDFS
Also seen asRSS 1.0 (RDF Site Summary) feeds; legacy Mozilla config (obsolete)
ToolsProtege, Apache Jena, Raptor (rapper), Altova XMLSpy
Related extensions.xml, .owl, .ttl, .jsonld, .n3
SpecificationW3C RDF 1.1 XML Syntax
Syntax at a glance

RDF/XML is plain text with no binary magic number. A file typically opens with an XML declaration <?xml version="1.0" encoding="UTF-8"?> and an <rdf:RDF …> root element that declares the XML namespaces (the vocabularies) it uses, at minimum xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#". Inside, each rdf:Description (or typed node) names a resource by IRI in its rdf:about attribute, and its child property elements carry the predicates and their object values — that is one triple per property. Non-XML RDF (Turtle .ttl, N-Triples .nt) holds the same triples without the XML wrapper.

What is an RDF file?

RDF stands for Resource Description Framework, a W3C standard for representing information as a graph of statements. The first RDF Recommendation appeared in 1999 and the current RDF 1.1 in 2014. An .rdf file is normally that graph written out in RDF/XML, the XML serialization of RDF, and its MIME type is application/rdf+xml. RDF is the foundation of the semantic web and linked data: it underlies OWL ontologies, SKOS vocabularies, FOAF profiles, Dublin Core metadata, and large knowledge graphs such as DBpedia and Wikidata exports.

The key idea is that RDF is a data model, not a document layout. There is no rendered view of an .rdf file, no page to look at, only a set of statements. The same data can be written in several syntaxes (Turtle .ttl, N-Triples .nt, JSON-LD .jsonld), and the .rdf extension specifically signals the RDF/XML form. The sections below explain the triple model, how RDF/XML encodes it element by element, and how to convert and query it.

The triple: subject, predicate, object

Every statement in RDF is a triple: a subject, a predicate and an object. The subject is the thing being described, the predicate is a property of it, and the object is the value of that property. Read as a sentence, <subject> <predicate> <object> means “the subject has this predicate with this value”.

<http://example.org/book/1>  dc:title       "RDF Primer" .
<http://example.org/book/1>  dc:creator     <http://example.org/person/42> .
<http://example.org/person/42> foaf:name      "Jane Doe" .

Two of the three positions are IRIs (internationalised URIs) that name things globally, so different files can talk about the same resource by using the same IRI, and merging two RDF files is just taking the union of their triples. Objects can be either an IRI (a link to another resource) or a literal (a plain value like a string or number, optionally with a datatype or a language tag). Because subjects and objects that are IRIs can be each other, a set of triples forms a directed graph: nodes are resources and literals, edges are predicates. That graph, not any particular file syntax, is what RDF actually is.

RDF/XML: how the graph becomes an XML tree

RDF/XML maps that graph onto XML elements. The document root is <rdf:RDF>, which declares the namespace prefixes for every vocabulary used. Inside, each described resource is an rdf:Description element (or a typed node element), and its properties are child elements.

<?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:foaf="http://xmlns.com/foaf/0.1/">

  <rdf:Description rdf:about="http://example.org/book/1">
    <dc:title>RDF Primer</dc:title>
    <dc:creator rdf:resource="http://example.org/person/42"/>
  </rdf:Description>

  <rdf:Description rdf:about="http://example.org/person/42">
    <foaf:name>Jane Doe</foaf:name>
  </rdf:Description>

</rdf:RDF>

The rdf:about attribute gives the subject’s IRI. Each child element name is a predicate, expanded from its namespace prefix (so dc:title is really http://purl.org/dc/elements/1.1/title). A property with text content, like <dc:title>RDF Primer</dc:title>, encodes a literal object; a property with an rdf:resource attribute and no content, like <dc:creator rdf:resource="…"/>, encodes an object that is another IRI. So the three-element block above is exactly the three triples from the previous section. RDF/XML also offers shorthand: rdf:type can be written as a typed node element (<foaf:Person> instead of <rdf:Description> plus a type triple), and nested Description elements can express a chain of triples inline, which is why the same graph can be serialized many different-looking ways.

Namespaces, vocabularies and why RDF reuses IRIs

RDF has no fixed set of predicates. Meaning comes from vocabularies, each identified by an IRI namespace, and a file mixes as many as it needs. RDFS and OWL define the vocabulary for describing classes and properties themselves; Dublin Core supplies bibliographic terms; FOAF describes people and their relationships; SKOS models thesauri and controlled vocabularies. Declaring xmlns:foaf="http://xmlns.com/foaf/0.1/" at the top simply lets the file abbreviate those long IRIs.

Because predicates and resources are global IRIs, RDF is designed for data to be linked across sources. One file can state facts about http://example.org/person/42 and a completely different file, published elsewhere, can add more facts about the same IRI; a triple store that loads both ends up with a single richer description of that person. This is the mechanism behind large knowledge graphs, where thousands of independently published RDF documents describe overlapping resources. An OWL ontology is itself RDF: its classes, properties and restrictions are triples using the OWL vocabulary, which is why Protege opens an OWL file and an .rdf file the same way.

Reading, converting and querying an .rdf

Because RDF/XML is XML text, the quickest way to see what an .rdf contains is to open it in a text editor (Notepad++, VS Code) or drag it into a browser, which shows the raw markup, the namespaces and the triples. A browser does not interpret the RDF; it just displays the XML tree. For real work you use a tool that understands the graph.

Converting between serializations is lossless because they all encode the same triples. The Raptor library’s rapper command does it in one line, rapper -i rdfxml -o turtle file.rdf, turning RDF/XML into the more readable Turtle; Apache Jena’s riot tool does the same and adds JSON-LD and N-Triples. Turtle writes the identical graph in a compact prefix-and-triple syntax with no XML noise, and JSON-LD expresses it as JSON for web applications. Querying uses SPARQL, RDF’s query language: a SELECT query matches triple patterns across the graph and returns a table of results, and you can export that table as CSV, though flattening a graph into rows is inherently lossy. This convert-and-query workflow, not a rename, is how you move RDF data between the XML world and other formats.

RDF versus XML, and other things that use .rdf

An .rdf file is valid XML, but RDF and XML are not the same kind of thing. XML is a generic markup syntax: any well-formed tree of elements. RDF is a data model (a graph of triples) that happens to be serialized using XML in the RDF/XML form. So while you can open an .rdf in any XML tool, its meaning is the graph, not the element nesting, and two very different-looking RDF/XML files can encode exactly the same triples. Renaming .rdf to .xml works for reading, but getting Turtle or JSON-LD out needs an RDF tool, not a plain XML rename.

The extension is also reused by a couple of unrelated things. RSS 1.0 (RDF Site Summary) is a news-feed format that is genuinely RDF/XML and was saved as .rdf, subscribed to in a feed reader; it is distinct from the far more common RSS 2.0 (.rss/.xml) and is rare today. Older Mozilla software (Firefox, Thunderbird) once used .rdf internally for bookmarks and extension manifests, but Mozilla removed RDF years ago, so a modern Firefox profile no longer relies on it. Both are separate uses of the same extension, not part of the semantic-web format described here.

XML parser risks: entity expansion and XXE

An .rdf file is text data with no executable code, so reading one is safe in itself. The exposure is at the XML parser level, and it is the same as for any untrusted XML. A “billion laughs” document defines a small entity that references itself in nested layers, so a naive parser expands it into gigabytes of memory and hangs, a denial-of-service with a tiny input. An XXE (XML external entity) attack declares an external entity pointing at a local file or an internal URL; a parser configured to resolve external entities will fetch that resource and can leak its contents into the parsed output or make the server issue requests on the attacker’s behalf. The defence is entirely on the reader: process untrusted RDF with a hardened XML parser that disables external entity resolution and limits or forbids DTD entity expansion, which every mainstream RDF library supports.

References