W3C

RDF/XML Syntax Specification (Revised)

W3C Working Draft 6 November 2002

This version:
http://www.w3.org/TR/2002/WD-rdf-syntax-grammar-20021106
Latest version:
http://www.w3.org/TR/rdf-syntax-grammar
Previous versions:
http://www.w3.org/TR/2002/WD-rdf-syntax-grammar-20020325
Editor:
Dave Beckett (University of Bristol)
Series editor:
Brian McBride (Hewlett Packard Labs)

Abstract

This specification defines an XML syntax for the Resource Description Framework (RDF) as amended and clarified by the RDF Core Working Group from that originally described in RDF Model & Syntax. The syntax is updated to be specified in terms of XML, XML Namespaces, the XML Information Set with new support for XML Base. The parts of the RDF/XML syntax are explained along with examples of how they work. The formal grammar is annotated with actions for generating the arcs that form the RDF graph as defined in the RDF Concepts and Abstract Syntax Working Draft. This is done using the N-Triples RDF Graph serializing format which enables more precise recording of the mapping in a machine processable form. These tests are gathered and published in the RDF Test Cases Working Draft.

Status of this Document

This is a W3C RDF Core Working Group Working Draft produced as part of the W3C Semantic Web Activity (Activity Statement). It incorporates decisions made by the Working Group updating the XML syntax for RDF from the original RDF Model & Syntax [RDF-MS] document in terms of the XML Information Set [INFOSET]. including new support for XML Base, RDF datatyping, rdf:nodeID for referencing Blank Nodes and rdf:parseType="Collection" for expressing a collection of nodes.

This document is being released for review by W3C Members and other interested parties to encourage feedback and comments, especially with regard to how the changes affect existing implementations and content. The current state is that it represents all the syntax as described in the grammar section of the original document, with some removed parts (see rdfms-abouteach), and the mapping to the RDF Graph is considered complete. The detailed changes from the previous 25 March 2002 draft are described in the Changes section however the main changes are as follows: Section 2 An XML syntax for RDF expanded with many more examples of the syntax, support for RDF Typed Literals using rdf:datatype was added, rdf:nodeID was added to allow referencing of Blank Nodes, rdf:parseType="Collection" was added for collections of Nodes, some non-namespaced attributes were returned to the grammar (see section 6.1.4 attribute-uri for the full list) and many other more minor changes after RDF Core Working Group decisions made since the last draft.

This is a public W3C Working Draft and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite as other than "work in progress". A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR/.

There are no known patent or IPR constraints associated with this Working Draft. The RDF Core Working Group Patent Disclosure page contains details, in conformance with W3C policy requirements.

Comments on this document are invited and should be sent to the public mailing list www-rdf-comments@w3.org. An archive of comments is available at http://lists.w3.org/Archives/Public/www-rdf-comments/.

Table of contents

1 Introduction
2 An XML syntax for RDF
  2.1 Introduction
  2.2 Node Elements and Property Elements
  2.3 Multiple Property Elements
  2.4 Empty Property Elements
  2.5 Property Attributes
  2.6 Completing the Document - Document Element and XML Declaration
  2.7 Languages - xml:lang
  2.8 XML Literals - rdf:parseType="Literal"
  2.9 Typed Literals - rdf:datatype
  2.10 Identifying Blank Nodes - rdf:nodeID
  2.11 Omitting Blank Nodes - rdf:parseType="Resource"
  2.12 Omitting Blank Nodes - Property Attributes on an empty Property Element
  2.13 Typed Node Elements
  2.14 Abbreviating URI References - rdf:ID and xml:base
  2.15 Container membership property elements - rdf:li and rdf:_n
  2.16 Collections - rdf:parseType="Collection"
  2.17 Reifying Statements - rdf:bagID and rdf:ID
  2.18 More Information
3 Terminology
4 RDF MIME type, file extension and Macintosh file type
5 Global Issues
  5.1 The RDF Namespace
  5.2 Identifiers
  5.3 Base URIs
  5.4 Constraints
6 Syntax Data Model
  6.1 Events
  6.2 Information Set Mapping
  6.3 Grammar Notation
7 RDF/XML Grammar
  7.1 Grammar Summary
  7.2 Grammar Productions
  7.3 Reification Rules
  7.4 List Expansion Rules
  7.5 Bag Expansion Rules
8 Serializing an RDF Graph to RDF/XML
9 RDF/XML in HTML
10 Acknowledgments
11 References

Appendices

A Issues affecting RDF/XML Syntax (Informative)
  A.1 Document Issues / Tasks (Informative)
  A.2 RDF Core Working Group Open Issues affecting RDF/XML Syntax (Informative)
  A.3 RDF Core Working Group Decided Issues affecting RDF/XML Syntax (Informative)
  A.4 RDF Core Working Group Postponed Issues affecting RDF/XML Syntax (Informative)
B Syntax Schemas (Informative)
  B.1 RELAX NG Compact Syntax Schema (Informative)
  B.2 Other Syntax Schemas (Informative)
C Changes (Informative)


1 Introduction

This document defines the XML [XML] syntax for RDF Graphs which was originally defined in the RDF Model & Syntax [RDF-MS] W3C Recommendation. Subsequent implementations of this syntax and comparison of the resulting RDF Graphs have shown that there was ambiguity - implementations generated different graphs and certain syntax forms were not widely implemented. These issues were generally made as either feedback to the www-rdf-comments@w3.org (archive) or from discussions on the RDF Interest Group list www-rdf-interest@w3.org (archive) .

The RDF Core Working Group is chartered to respond to the need for a number of fixes, clarifications and improvements to the specification of RDF's abstract graph and XML syntax. The Working Group invites feedback from the developer community on the effects of its proposals on existing implementations and documents.

Several decisions including amendments and deletions to the grammar are referred to below. The definitive record of the decisions is the RDF Core Working Group issues list.

This document revises the original RDF/XML grammar in terms of XML Information Set [INFOSET] Information Items which moves away from the rather low-level details of XML, such as particular forms of empty elements. This allows the grammar to be more precisely recorded and the mapping from the XML syntax to the RDF Graph more clearly shown. The mapping to the RDF Graph is done by emitting statements in the form defined in the N-Triples section of RDF Test Cases [RDF-TESTS] Working Draft which creates an RDF Graph, that has semantics defined by RDF Semantics [RDF-SEMANTICS] Working Draft.

The complete specification of RDF consists of a number of documents:

2 An XML syntax for RDF

This section introduces the RDF/XML syntax, describes how it encodes RDF Graphs and explains this with examples. If there is any conflict between this informal description and the formal description of the syntax and grammar in sections 6 Syntax Data Model and 7 RDF/XML Grammar, the latter two sections take precedence.

Editors Note: This section has substantially changed in this version of the working draft and although the substance is not expected to change, it is likely that it will go substantial editorial revision. The Working Group particularly invites feedback on this section.

2.1 Introduction

The RDF Concepts and Abstract Syntax [RDF-CONCEPTS] working draft defines the RDF Graph data model (Section 2.3.1) and the RDF Graph syntax (Section 4.2). Along with the RDF Semantics [RDF-SEMANTICS] working draft this provides an abstract syntax with a formal semantics for it. The RDF Graph has Nodes and labeled directed Arcs that link pairs of Nodes and this is represented as a set of RDF triples where each triple contains a Subject Node, Property Arc and Object Node. Nodes are RDF URI References, RDF Literals or are Blank Nodes and for encoding in syntaxes may be given a document-local, non-RDF URI References identifier called a Blank Node Identifier. Arcs are labeled with RDF URI References. The property arc can be interpreted as either a relationship between two nodes or as defining an attribute value (object node) for some subject node.

In order to encode the graph in XML, the nodes and arcs have to be represented by XML element names, attribute names, element content and attribute content. RDF/XML uses XML QNames to represent RDF URI References. The namespace prefix part of all QNames is associated with a RDF URI Reference as defined in XML Namespaces [XML-NS]. The RDF URI Reference represented by a QName is determined by appending the local name part of the QName to the RDF URI Reference associated with the namespace prefix part of the QName. This is used to shorten the RDF URI References of all property arcs labels and some nodes. RDF URI References identifying subject and object nodes can also be stored as XML attribute values or XML element names via QNames. RDF Literals (which are only object nodes) become either XML element text content or XML attribute values.

A graph can be considered a collection of paths of the form Node, Arc, Node, Arc, Node, Arc, ... Node which cover the entire graph. In RDF/XML these turn into sequences of elements inside elements which alternate between elements for Nodes and Arcs. This has been called a series of Node/Arc stripes. The Node at the start of the sequence turns into the outermost element, the next arc turns into a child element, and so on. The stripes generally start at the top of an RDF/XML document and always begin with nodes.

Several RDF/XML examples are given in the following sections building up to complete RDF/XML documents. Example 7 is the first complete RDF/XML document.

2.2 Node Elements and Property Elements

Graph for RDF/XML Example
Figure 1: Graph for RDF/XML Example (SVG version)

An RDF Graph is given in Figure 1 where the nodes are represented as ovals and contain their RDF URI References where they have them, all the arcs are labeled with RDF URI References and Plain Literal nodes have been written in rectangles.

If we follow one Node, Arc ... , Node path through the graph shown in Figure 2:

One Path Through the Graph
Figure 2: One Path Through the Graph (SVG version)

This corresponds to the Node/Arc stripes:

  1. Node with RDF URI Reference http://www.w3.org/TR/rdf-syntax-grammar
  2. Arc labeled with RDF URI Reference http://example.org/terms/editor
  3. Node with no RDF URI Reference
  4. Arc labeled with RDF URI Reference http://example.org/terms/homePage
  5. Node with RDF URI Reference http://purl.org/net/dajobe/

In RDF/XML, the sequence of 5 nodes and arcs in Figure 2 corresponds to the usage of 5 XML elements of two types, for the graph nodes and arcs. These are conventionally called Node Elements and Property Elements respectively. In the striping shown in Example 1, rdf:Description is the node element (used 3 times for the three nodes) and ex:editor and ex:homePage are the 2 property elements.

Example 1: Striped RDF/XML (nodes and arcs)
<rdf:Description>
  <ex:editor>
    <rdf:Description>
      <ex:homePage>
        <rdf:Description>
        </rdf:Description>
      </ex:homePage>
    </rdf:Description>
  </ex:editor>
</rdf:Description>

The Figure 2 graph consists of some nodes that are RDF URI References (and others that are not) and this can be added to the RDF/XML using the rdf:about attribute on node elements to give the result in Example 2:

Example 2: Node Elements with RDF URI References added