treetriples Syntax Specification

1. Introduction

treetriples is an XML-based RDF syntax.  It aims to take the best qualities from existing syntaxes:

  1. The ability to process RDF using XSLT, as in TriX and RXR.
  2. The intuitive structure of Turtle.
  3. To approach the conciseness and human-readability of RDF/XML.

1.1. Definitions

treetriples uses the following XML namespace for the elements defined by this specification:

Note that the prefix used in this document is ‘tt’, but any prefix may be used, or documents may place treetriples elements into the default namespace.

In this document, where XML fragments are shown, XML namespace prefixes should be interpreted as if the following namespace mappings were in scope:

Prefix URI

In this document, where an XML entity reference from the list of prefixes above is used, it should also be interpreted as if it had the corresponding URI value from the table above.

This document uses the term URI [RFC3986] to refer to what the RDF Concepts Recommendation [RDF] refers to as an "RDF URI Reference" [RDFURI].  This is basically an absolute IRI with an optional fragment part.

1.2. Examples

Below is an example of a treetriples document:

<!DOCTYPE rdf [
<!ENTITY rdf "">
<!ENTITY ex "">

<rdf xmlns="">

  <s id="">
    <p id="&ex;bag">
      <o id="_:b1" />
    <p id="&ex;bnode">
      <o id="_:b2" />
    <p id="&ex;lang">
      <o xml:lang="en">English Literal</o>
    <p id="&ex;list">
      <o id="_:b0" />
    <p id="&ex;plain">
      <o>Plain Literal</o>
    <p id="&ex;uri">
      <o id="" />
    <p id="&ex;xml">
      <o parse="xml">
      Below is:
      <html:div xmlns:html="">Some <html:b>mixed</html:b> content.</html:div>

  <s id="_:b2">
    <p id="&rdf;type">
      <o id="&ex;Type"></o>
    <p id="&ex;number">
      <o datatype="">7</o>

  <d parse="list">
    <o id="" listId="_:b0" />
    <o id="" />

  <d parse="bag" id="_:b1">

The equivalent in RDF/XML is:

<rdf:RDF xmlns:rdf=""

  <rdf:Description rdf:about="">
    <ex:plain>Plain Literal</ex:plain>
    <ex:lang xml:lang="en">English Literal</ex:lang>
    <ex:list rdf:parseType="Collection">
      <rdf:Description rdf:about="" />
      <rdf:Description rdf:about="" />
    <ex:xml rdf:parseType="Literal">
      Below is:
      <html:div>Some <html:b>mixed</html:b> content.</html:div>
    <ex:uri rdf:resource="" />
    <ex:bnode rdf:nodeID="b2" />

  <ex:Type rdf:nodeID="b1">
    <ex:number rdf:datatype="">7</ex:number>


2. Syntactic Constructs


2.1. Id constructs: BNodes and URIs

'id' attributes are used to represent URIs and Bnode identifiers in treetriples documents.  The same syntax is also used by 'listId' and 'stmtId' attributes to represent the ids of list nodes and reified statements.  That syntax is described below:

If an Id construct starts with the string '_:' (underscore colon), then it is a bnode identifier, otherwise it is a URI.

2.1.1. Bnode identifiers

Bnode identifiers give bnodes document-scoped ids so that the bnode can be referenced  from elsewhere in the document.

The syntax of a bnode id is restricted by the following regular expression:


That is, an underscore (_); a colon (:); a letter (a-z or A-Z) or underscore (_); followed by zero or more of: a letter (a-z or A-Z), digit (0-9), full-stop (.), hyphen (-), or underscore (_).

2.1.2. URIs

URIs used in id constructs:

  1. MUST conform to RDF URI Reference described by RDF [RDFURI]; and
  2. MUST be absolute.

2.2. Objects: Resources, Literals, and XML

The <tt:o> element is used in this document to represent the object of a triple.  The object of a triple is one of:

  1. A plain literal
  2. A plain literal with a language tag
  3. A data-typed literal
  4. An XML literal
  5. A bnode
  6. A URI

2.2.1. Plain literals

A <tt:o> element, with no attributes represents a plain literal.  The text content of the element, if any, represents the literal value.


<tt:o>A plain literal</tt:o>

A blank literal can be represented as:


2.2.2. Plain literals with language tags

A <tt:o> element with an xml:lang attribute represents a plain literal with a language tag.  The value of xml:lang represents the language of the literal as a [RFC3066] language tag (as used by RDF/XML).  The text content of the element, if any, represents the literal value.


<tt:o xml:lang="de">Guten Tag!</tt:o>

Note that because xml:lang is only allowed to appear in this single place, there is no inheritance of xml:lang context.

2.2.3. Data-typed literals

A <tt:o> element with a datatype attribute represents a typed literal.  The value of the datatype attribute is the datatype URI.  The text content of the element, if any, represents the literal value.


<tt:o datatype="">2000-01-01T12:00:00Z</tt:o>

The datatype URI MUST be a legal RDF datatype, as defined by the RDF Concepts Recommendation [RDF].

2.2.4. XML Literals

A <tt:o> element with a parse="xml" attribute represents an XML literal.  The child content of the element, if any, represents the value of the literal.


<tt:o parse="xml">
Below is:
<html:div>Some <html:b>mixed</html:b> content.</html:div>

Consumers wishing to obtain the stringified value of an XML Literal must convert the contents of the <tt:o> element to Exclusive Canonical XML with comments and an empty Inclusive NamespaceList, then convert the UTF-8 bytes back to a character string.  This is the same process as required by RDF/XML.

The contents of a well-formed XML Literal is not restricted by this document.  Any requirements made by this document, such as to the contents of id attributes, or the occurrence of tt: namespaced elements do not apply to the children of the <tt:o> element.

2.3. Generic Triples Syntax


2.4. Declarations

2.4.1. Containers

A <tt:d> element, with a parse attribute containing one of the values below, represents a container:

parse attribute rdf:type 
alt rdf:Alt
bag rdf:Bag
seq rdf:Seq
container none

The element  MUST have an id attribute representing the URI or bnode identifier of the container.

The parse attribute values: alt, bag, and seq, denote a triple, with the resource represented by the id attribute as its subject; the predicate rdf:type; and the corresponding rdf:type value as the object.  Elements with a parse="container" attribute, do not implicitly create an rdf:type triple.

Inside the element, one or more <tt:o> elements represent each consecutive member of the container.  The first child element represents a triple with the resource represented by the id attribute as its subject; the predicate rdf:_1; and the resource represented by the <tt:o> element as its  object.  Subsequent child elements represent triples with the predicates rdf:_2, rdf:_3, etc.

2.4.2. Collections


2.4.2. Reification


3. Restrictions


3.1. Duplicate Subjects and Predicates


3.2. Well-formed Containers


3.3. Well-formed Collections


3.4. Well-formed Reified Statements


3.5. Well-formed XML literals


4. References

4.1. Normative References

"Resource Description Framework (RDF): Concepts and Abstract Syntax"
"Extensible Markup Language (XML) 1.0 (Fourth Edition)"
"Namespaces in XML 1.0 (Second Edition)"
"XML Schema Part 2: Datatypes Second Edition"
"Tags for the Identification of Languages"
“Internationalized Resource Identifiers (IRIs)”

4.2. Informative References

"Turtle - Terse RDF Triple Language"
"RDF/XML Syntax Specification (Revised)"
"RDF Triples in XML"
"Modernising Semantic Web Markup"
"XML Path Language (XPath) Version 1.0"
"XSL Transformations (XSLT)"