This document has been reviewed by W3C Members and other interested
parties, and it has been endorsed by the Director as a W3C
Recommendation. W3C's role in making the Recommendation is to
draw attention to the specification and to promote its widespread
deployment. This enhances the functionality and interoperability of
the Web.

This section describes the status of this document at the time of its
publication. Other documents may supersede this document. A list of current W3C
publications and the latest revision of this technical report can be found in
the W3C technical reports index at
http://www.w3.org/TR/.

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.

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.

In order to encode the graph in XML, the nodes and predicates have to be
represented in XML terms — element names, attribute names, element contents
and attribute values.
RDF/XML uses XML
QNames
as defined in Namespaces in XML[XML-NS]
to represent
RDF URI references.
All QNames have a namespace name which is a URI reference
and a short
local name.
In addition, QNames can either have a short
prefix
or be declared with the default namespace declaration and have none (but
still have a namespace name)

The
RDF URI reference
represented by a QName is determined by appending the
local name
part of the QName after the
namespace name (URI reference) part of the QName.
This is used to shorten the
RDF URI references
of all predicates and some nodes.
RDF URI references identifying
subject and object nodes can also be stored as XML attribute values.
RDF literals,
which can only be 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,
predicate arc, node, predicate arc, node, predicate 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 predicate 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 predicate 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.

In RDF/XML, the sequence of 5 nodes and predicate arcs on
the left hand side of Figure 2 corresponds to
the usage of five XML elements of two types, for the graph nodes and
predicate 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 three times for the three nodes) and
ex:editor and ex:homePage are the two
property elements.

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:

Adding the other two paths through the Figure 1
graph to the RDF/XML in
Example 2
gives the result in Example 3
(this example fails to show that the blank node is
shared between the two paths, see
2.10):

There are several abbreviations that can be used to make common
uses easier to write down. In particular, it is common that a
subject node in the RDF graph has multiple outgoing predicate arcs. RDF/XML
provides an abbreviation for the corresponding syntax when a node
element about a resource has multiple property elements. This can be
abbreviated by using multiple child property elements inside the node
element describing the subject node.

Taking Example 3, there are
two node elements that can take multiple property elements.
The subject node with URI reference
http://www.w3.org/TR/rdf-syntax-grammar
has property elements ex:editor and ex:title
and the node element for the blank node can take ex:homePage
and ex:fullName. This abbreviation
gives the result shown in Example 4
(this example does show that there is a single blank node):

When a predicate arc in an RDF graph points to an object node which has no
further predicate arcs, which appears in RDF/XML as an empty node element
<rdf:Description rdf:about="..."></rdf:Description>
(or <rdf:Description rdf:about="..." />)
this form can be shortened. This is done by using the
RDF URI reference
of the object node as the value of an XML attribute rdf:resource
on the containing property element and making the property element empty.

In this example, the property element ex:homePage
contains an empty node element with the
RDF URI referencehttp://purl.org/net/dajobe/. This can be replaced with
the empty property element form giving the result shown in
Example 5:

When a property element's content is string literal,
it may be possible to use it as an XML attribute on the
containing node element.
This can be done for multiple properties on the same node element
only if the property element name is not repeated
(required by XML — attribute names are unique on an XML element)
and any in-scope xml:lang on the
property element's string literal (if any) are the same (see Section 2.7)
This abbreviation is known as a Property Attribute
and can be applied to any node element.

This abbreviation can also be used when the property element is
rdf:type and it has an rdf:resource attribute
the value of which is interpreted as a
RDF URI reference object node.

In Example 5:,
there are two property elements with string literal content,
the dc:title and ex:fullName
property elements. These can be replaced with property attributes
giving the result shown in Example 6:

To create a complete RDF/XML document, the serialization of the
graph into XML is usually contained inside an rdf:RDF
XML element which becomes the top-level XML document element.
Conventionally the rdf:RDF element is also used to
declare the XML namespaces that are used, although that is not
required. When there is only one top-level node element inside
rdf:RDF, the rdf:RDF can be omitted
although any XML namespaces must still be declared.

The XML specification also permits an XML declaration at
the top of the document with the XML version and possibly the XML
content encoding. This is optional but recommended.

Completing the RDF/XML could be done for any of the correct
complete graph examples from
Example 4 onwards but taking the smallest
Example 6 and adding the final components,
gives a complete RDF/XML representation of the original
Figure 1 graph
in Example 7:

RDF/XML permits the use of the xml:lang attribute as defined by
2.12 Language Identification
of XML 1.0[XML]
to allow the identification of content language.
The xml:lang attribute can be used on any node element or property element
to indicate that the included content is in the given language.
Typed literals
which includes XML literals
are not affected by this attribute.
The most specific in-scope language present
(if any) is applied to property element string literal content or
property attribute values. The xml:lang="" form
indicates the absence of a language identifier.

Some examples of marking content languages for RDF properties are shown in
Example 8:

RDF allows
XML literals
([RDF-CONCEPTS] Section 5, XML Content within an RDF graph)
to be given as the object node of a predicate.
These are written in RDF/XML as content of a property element (not
a property attribute) and indicated using the
rdf:parseType="Literal" attribute on the containing
property element.

An example of writing an XML literal is given in
Example 9 where
there is a single RDF triple with the subject node
RDF URI referencehttp://example.org/item01, the predicate
RDF URI referencehttp://example.org/stuff/1.0/prop (from
ex:prop) and the object node with XML literal
content beginning a:Box.

RDF allows
typed literals
to be given as the object node of a predicate. Typed literals consist of a literal
string and a datatype
RDF URI reference. These are written in RDF/XML using
the same syntax for literal string nodes in the property element form
(not property attribute) but with an additional
rdf:datatype="datatypeURI"
attribute on the property element. Any
RDF URI reference can be used in the attribute.

Blank nodes (not RDF URI reference nodes) in RDF graphs can be written
in a form that allows the
<rdf:Description></rdf:Description> pair to be omitted.
The omission is done by putting an
rdf:parseType="Resource"
attribute on the containing property element
that turns the property element into a property-and-node element,
which can itself have both property elements and property attributes.
Property attributes and the rdf:nodeID attribute
are not permitted on property-and-node elements.

Taking the earlier Example 7,
the contents of the ex:editor property element
could be alternatively done in this fashion to give
the form shown in Example 12:

If all of the property elements on a blank node element have
string literal values with the same in-scope xml:lang
value (if present) and each of these property elements appears at
most once and there is at most one rdf:type property
element with a RDF URI reference object node, these can be abbreviated by
moving them to be property attributes on the containing property
element which is made an empty element.

Taking the earlier Example 5,
the ex:editor property element contains a
blank node element with two property elements
ex:fullname and ex:homePage.
ex:homePage is not suitable here since it
does not have a string literal value, so it is being
ignored for the purposes of this example.
The abbreviated form removes the ex:fullName property element
and adds a new property attribute ex:fullName with the
string literal value of the deleted property element
to the ex:editor property element.
The blank node element becomes implicit in the now empty
ex:editor property element. The result is shown in
Example 13.

It is common for RDF graphs to have rdf:type predicates
from subject nodes. These are conventionally called typed
nodes in the graph, or typed node elements in the
RDF/XML. RDF/XML allows this triple to be expressed more concisely.
by replacing the rdf:Description node element name with
the namespaced-element corresponding to the
RDF URI reference of the value of
the type relationship. There may, of course, be multiple rdf:type
predicates but only one can be used in this way, the others must remain as
property elements or property attributes.

The typed node elements are commonly used in RDF/XML with the built-in
classes in the RDF vocabulary:
rdf:Seq, rdf:Bag, rdf:Alt,
rdf:Statement, rdf:Property and
rdf:List.

RDF/XML allows further abbreviating RDF URI references in XML attributes in two
ways. The XML Infoset provides a base URI attribute xml:base
that sets the base URI for resolving relative RDF URI references, otherwise the base URI is that of the document. The base URI applies to
all RDF/XML attributes that deal with RDF URI references which are rdf:about,
rdf:resource, rdf:ID
and rdf:datatype.

The rdf:ID attribute on a node element (not property
element, that has another meaning) can be used instead of
rdf:about and gives a relative RDF URI reference equivalent to #
concatenated with the rdf:ID attribute value. So for
example if rdf:ID="name", that would be equivalent
to rdf:about="#name". rdf:ID provides an additional
check since the same name can only appear once in the
scope of an xml:base value (or document, if none is given),
so is useful for defining a set of distinct,
related terms relative to the same RDF URI reference.

Both forms require a base URI to be known, either from an in-scope
xml:base or from the URI of the RDF/XML document.

Example 16 shows abbreviating the node
RDF URI reference of http://example.org/here/#snack using an
xml:base of http://example.org/here/ and
an rdf:ID on the rdf:Description node element.
The object node of the ex:prop predicate is an
absolute RDF URI reference
resolved from the rdf:resource XML attribute value
using the in-scope base URI to give the
RDF URI referencehttp://example.org/here/fruit/apple.

RDF has a set of container membership properties
and corresponding property elements that are mostly used with
instances of the
rdf:Seq, rdf:Bag and rdf:Alt
classes which may be written as typed node elements. The list properties are
rdf:_1, rdf:_2 etc. and can be written
as property elements or property attributes as shown in
Example 17. There is an rdf:li
special property element that is equivalent to
rdf:_1, rdf:_2 in order,
explained in detail in section 7.4.
The mapping to the container membership properties is
always done in the order that the rdf:li special
property elements appear in XML — the document order is significant.
The equivalent RDF/XML to Example 17 written
in this form is shown in Example 18.

RDF/XML allows an rdf:parseType="Collection"
attribute on a property element to let it contain multiple node
elements. These contained node elements give the set of subject
nodes of the collection. This syntax form corresponds to a set of
triples connecting the collection of subject nodes, the exact triples
generated are described in detail in
Section 7.2.19 Production parseTypeCollectionPropertyElt.
The collection construction is always done in the order that the node
elements appear in the XML document. Whether the order of the
collection of nodes is significant is an application issue and not
defined here.

Example 19 shows a collection of three
nodes elements at the end of the ex:hasFruit
property element using this form.

The rdf:ID attribute can be used on a property
element to reify the triple that it generates (See
section 7.3 Reification Rules for the
full details).
The identifier for the triple should be constructed as a
RDF URI reference
made from the relative URI reference
# concatenated with the rdf:ID attribute
value, resolved against the in-scope base URI. So for example if
rdf:ID="triple", that would be equivalent to the RDF URI reference
formed from relative URI reference #triple against the base URI.
Each (rdf:ID attribute value, base URI)
pair has to be unique in an RDF/XML document,
see constraint-id.

Example 20 shows a rdf:ID
being used to reify a triple made from the ex:prop
property element giving the reified triple the
RDF URI referencehttp://example.org/triples/#triple1.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in
this document are to be interpreted as described in
RFC 2119[KEYWORDS].

All use of string without further qualification refers to
a Unicode[UNICODE] character string;
a sequence of characters represented by a code point in Unicode.
(Such as defined in [CHARMOD] in section
3.4 Strings).

Note (Informative):
The names aboutEach and aboutEachPrefix were removed
from the language and the RDF vocabulary by the RDF Core Working Group.
See the resolution of issues
rdfms-abouteach and
rdfms-abouteachprefix
for further information.

The
RDF namespace URI reference (or namespace name) is
http://www.w3.org/1999/02/22-rdf-syntax-ns#
and is typically used in XML with the prefix rdf
although other prefix strings may be used.
The RDF Vocabulary
is identified by this namespace name and consists of the following names only:

Syntax names — not concepts

RDF Description ID about parseType resource li nodeID datatype

Class names

Seq Bag Alt Statement Property XMLLiteral List

Property names

subject predicate object type value first rest _n
where n is a decimal integer greater than zero with no leading zeros.

Resource names

nil

Any other names are not defined and SHOULD generate a warning when
encountered, but should otherwise behave normally.

Within RDF/XML documents it is not permitted to use XML namespaces
whose namespace name is the
·RDF namespace URI reference·
concatenated with additional characters.

Within RDF/XML, XML QNames are transformed into
RDF URI references
by appending the XML local name to the namespace name (URI reference).
For example, if the XML namespace prefix foo has
namespace name (URI reference)
http://example.org/somewhere/ then the QName
foo:bar would correspond to the RDF URI reference
http://example.org/somewhere/bar. Note that this
restricts which
RDF URI references can be made and the same URI can be given in multiple ways.

Blank nodes have distinct identity in the RDF graph.
When the graph is written in a syntax such as RDF/XML, these
blank nodes may need graph-local identifiers and a syntax
in order to preserve this distinction. These local identifiers are called
blank node identifiers
and are used in RDF/XML as values of the rdf:nodeID attribute
with the syntax given in Production nodeIdAttr.
Blank node identifiers in RDF/XML are scoped to the XML Information Set
document information item.

If no blank node identifier is given explicitly as an
rdf:nodeID attribute value then one will need to be
generated (using generated-blank-node-id, see section 6.3.3).
Such generated blank node
identifiers must not clash with any blank node identifiers derived
from rdf:nodeID attribute values. This can be
implemented by any method that preserves the distinct identity of all
the blank nodes in the graph, that is, the same blank node identifier
is not given for different blank nodes. One possible method would be
to add a constant prefix to all the rdf:nodeID attribute
values and ensure no generated blank node identifiers ever used that
prefix. Another would be to map all rdf:nodeID attribute
values to new generated blank node identifiers and perform that mapping
on all such values in the RDF/XML document.

Each application of production idAttr
matches an attribute. The pair formed by the
·string-value·
accessor of the matched attribute and the
·base-uri·
accessor of the matched attribute is unique within a single RDF/XML
document.

This document specifies the syntax of RDF/XML as a grammar on an
alphabet of symbols. The symbols are called events in the
style of the [XPATH]Information Set Mapping.
A sequence of events is normally derived from an XML document, in
which case they are in document order as defined below in
Section 6.2 Information Set Mapping.
The sequence these events form are intended to be similar to the sequence
of events produced by the [SAX2] XML API from
the same XML document. Sequences of events may be checked against
the grammar to determine whether they are or are not syntactically
well-formed RDF/XML.

The grammar productions may include actions which fire when the
production is recognized. Taken together these actions define a
transformation from any syntactically well-formed RDF/XML sequence of
events into an RDF graph represented in the
N-Triples
language.

The model given here illustrates one way to create a representation of
an RDF Graph
from an RDF/XML document. It does not mandate any implementation
method — any other method that results in a representation of the same
RDF Graph
may be used.

Other information items and properties have no mapping to
syntax data model events.

Element information items with reserved XML Names
(See Name
in XML 1.0)
are not mapped to data model element events. These are all those
with property [prefix] beginning with xml (case
independent comparison) and all those with [prefix] property
having no value and which have [local name] beginning with
xml (case independent comparison).

There are nine types of event defined in the following subsections.
Most events are constructed from an Infoset information item (except
for URI reference,
blank node,
plain literal and
typed literal). The effect
of an event constructor is to create a new event with a unique identity,
distinct from all other events. Events have accessor operations on them
and most have the string-value accessor that may be a static value
or computed.

Made from the value of element information item property [attributes] which is a set of attribute information items.

If this set contains an attribute information item xml:lang (
[namespace name] property with the value
"http://www.w3.org/XML/1998/namespace" and
[local name] property value "lang")
it is removed from the set of attribute information items and the
·language· accessor is set to the
[normalized-value] property of the attribute information item.

All remaining reserved XML Names
(See Name
in XML 1.0)
are now removed from the set. These are, all
attribute information items in the set with property [prefix]
beginning with xml (case independent
comparison) and all attribute information items with [prefix]
property having no value and which have [local name] beginning with
xml (case independent comparison) are removed.
Note that the [base URI] accessor is computed by XML Base before any
xml:base attribute information item is deleted.

The remaining set of attribute information items are then used
to construct a new set of
Attribute Events
which is assigned as the value of this accessor.

Set from the
·attributes·
as described above.
If no value is given from the attributes, the value is set to the value of
the language accessor on the parent event (either a
Root Event or an
Element Event), which may be the empty string.

Set to the value of the attribute information item property [normalized value] as specified by
[XML] (if an attribute whose normalized
value is a zero-length string, then the string-value is also
a zero-length string).

The support for a limited set of non-namespaced names is
REQUIRED and intended to allow RDF/XML documents specified in
[RDF-MS] to remain valid; new documents
SHOULD NOT use these unqualified attributes and applications MAY
choose to warn when the unqualified form is seen in a document.

The construction of
RDF URI references
from XML attributes can generate the same
RDF URI references
from different XML attributes. This can cause ambiguity in the
grammar when matching attribute events (such as when
rdf:about and about XML attributes are
both present). Documents that have this are illegal.

The value is a function of the value of the
·identifier· accessor.
The value begins with "_:" and the entire value MUST match the
N-TriplesnodeID production.
The function MUST preserve distinct blank node identity as discussed in in section 5.2 Identifiers.

These events are constructed by giving a value for the
·identifier· accessor.

For further information on identifiers in the RDF graph, see
section 5.2.

The value is the concatenation of the following in this order
""" (1 double quote),
the escaped value of the
·literal-value· accessor,
""" (1 double quote), "^^<",
the escaped value of the
·literal-datatype· accessor
and ">".

Interoperability Note (Informative):
Literals beginning with a Unicode combining character are
allowed however they may cause interoperability problems.
See [CHARMOD] for further information.

Implementation Note (Informative):
In XML Schema (part 1)[XML-SCHEMA1],
white space normalization
occurs during validation according to the value of the whiteSpace
facet. The syntax mapping used in this document occurs after this,
so the whiteSpace facet formally has no further effect.

To transform the Infoset into the sequence of events
in document order, each
information item is transformed as described above to generate a
tree of events with accessors and values. Each element event is
then replaced as described below to turn the tree of events
into a sequence in document order.

The following notation is used to describe matching the sequence
of data model events as given in Section 6
and the actions to perform for the matches.
The RDF/XML grammar is defined in terms of mapping from these matched
data model events to triples, using notation of the form:

where the event-content is an expression matching
event-types (as defined in Section 6.1),
using notation given in the following sections.
The number is used for reference purposes.
The grammar action may include generating
new triples to the graph, written in
N-Triples
format.

The following sections describe the general notation used and that
for event matching and actions.

If the RDF/XML is a standalone XML document
(identified by presentation as an
application/rdf+xml RDF MIME type object,
or by some other means) then the grammar may start with
production doc or
production nodeElement.

If the content is known to be RDF/XML by context, such as when
RDF/XML is embedded inside other XML content, then the grammar
can either start
at Element EventRDF
(only when an element is legal at that point in the XML)
or at production nodeElementList
(only when element content is legal, since this is a list of elements).
For such embedded RDF/XML, the
·base-uri·
value on the outermost element must be initialized from the containing
XML since no
Root Event will be available.
Note that if such embedding occurs, the grammar may be entered
several times but no state is expected to be preserved.

If element e has
e.URI =
rdf:li then apply the list expansion rules on element e.parent in
section 7.4
to give a new URI u and
e.URI := u.

The action of this production must be done before the
actions of any sub-matches (resourcePropertyElt ... emptyPropertyElt).
Alternatively the result must be equivalent to as if it this action
was performed first, such as performing as the first
action of all of the sub-matches.

For element e and the literal l
that is the rdf:parseType="Literal" content.
l is not transformed by the syntax data model mapping into events
(as noted in 6 Syntax Data Model)
but remains an XML Infoset of XML Information items.

l is transformed into the lexical form of an
XML literal
in the RDF graph x (a Unicode string)
by the following algorithm. This does not mandate any implementation
method — any other method that gives the same result may be used.

All rdf:parseType attribute values other than the strings
"Resource", "Literal" or "Collection" are treated as if the value was
"Literal". This production matches and acts as if production
parseTypeLiteralPropertyElt
was matched.
No extra triples are generated for other rdf:parseType values.

Use property names that cannot be turned into XML namespace-qualified names.

An XML namespace-qualified name
(QName)
has restrictions on the legal characters such that not all property URIs
can be expressed as these names.
It is recommended that implementors of RDF serializers, in order to
break a URI into a namespace name and a local name, split it after
the last XML non-NCName
character, ensuring that the first character of the name is a
Letter or '_'.
If the URI ends in a
non-NCName
character then throw a "this graph cannot be serialized in RDF/XML"
exception or error.

Use inappropriate reserved names as properties

For example, a property with the same URI as any of the
syntaxTerms production.

Implementation Note (Informative):
When an RDF graph is serialized to RDF/XML and has an XML Schema
Datatype (XSD), it SHOULD be written in a form that does not require
whitespace processing. XSD support is NOT required by RDF or RDF/XML
so this is optional.

If RDF/XML is embedded inside HTML or XHTML this can
add many new elements and attributes, many of which will not be
in the appropriate DTD. This embedding causes validation against the DTD to fail.
The obvious solution of changing or extending the DTD is not practical
for most uses. This problem has been analyzed extensively by Sean B. Palmer in
RDF in HTML: Approaches[RDF-IN-XHTML]
and it concludes that there is no single embedding
method that satisfies all applications and remains simple.

The recommended approach is to not embed RDF/XML in HTML/XHTML but
rather to use <link> element in the <head>
element of the HTML/HTML to point at a separate RDF/XML document.
This approach has been used for several years by the
Dublin Core Metadata Initiative (DCMI)
on its Web site.

To use this technique, the <link> element
href should point at the URI of the RDF/XML content
and the type attribute should be used with the value of
"application/rdf+xml", the proposed MIME type for
RDF/XML, see Section 4

Namespaces in XML, T. Bray, D. Hollander and A. Layman, Editors. World Wide Web Consortium. 14 January 1999. This version is http://www.w3.org/TR/1999/REC-xml-names-19990114. The latest version of Namespaces in XML is available at http://www.w3.org/TR/REC-xml-names.

XML Base, J. Marsh, Editor, W3C Recommendation. World Wide Web Consortium, 27 June 2001. This version of XML Base is http://www.w3.org/TR/2001/REC-xmlbase-20010627. The latest version of XML Base is at http://www.w3.org/TR/xmlbase.

The Unicode Standard, Version 3, The Unicode
Consortium, Addison-Wesley, 2000. ISBN 0-201-61633-5, as updated
from time to time by the publication of new versions. (See http://www.unicode.org/unicode/standard/versions/
for the latest version and additional information on versions of
the standard and of the Unicode Character Database).

RDF
Primer, F. Manola, E. Miller, Editors, W3C Recommendation, 10 February 2004. This
version is
http://www.w3.org/TR/2004/REC-rdf-primer-20040210/. The latest version is at
http://www.w3.org/TR/rdf-primer/.

These are are divided into non-editorial and editorial. The
non-editorial changes also list consquential editorial changes.
Editorial changes are those which do not result in any change in the
meaning of an RDF document or the behaviour of an RDF
application.