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:

http://djpowell.net/schemas/treetriples/1/

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
tt http://djpowell.net/schemas/treetriples/1/
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs http://www.w3.org/2000/01/rdf-schema#
dc http://purl.org/dc/elements/1.1/
ex http://example.com/vocab#
rss http://purl.org/rss/1.0/
foaf http://xmlns.com/foaf/0.1/
html http://www.w3.org/1999/xhtml

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 "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY ex "http://www.example.com/vocab#">
]>

<rdf xmlns="http://djpowell.net/schemas/treetriples/1/">

  <s id="http://www.example.com/thing/1/">
    <p id="&ex;bag">
      <o id="_:b1" />
    </p>
    <p id="&ex;bnode">
      <o id="_:b2" />
    </p>
    <p id="&ex;lang">
      <o xml:lang="en">English Literal</o>
    </p>
    <p id="&ex;list">
      <o id="_:b0" />
    </p>
    <p id="&ex;plain">
      <o>Plain Literal</o>
    </p>
    <p id="&ex;uri">
      <o id="http://www.example.com/thing/4/" />
    </p>
    <p id="&ex;xml">
      <o parse="xml">
      Below is:
      <html:div xmlns:html="http://www.w3.org/1999/xhtml">Some <html:b>mixed</html:b> content.</html:div>
    </o>
    </p>
  </s>

  <s id="_:b2">
    <p id="&rdf;type">
      <o id="&ex;Type"></o>
    </p>
    <p id="&ex;number">
      <o datatype="http://www.w3.org/2001/XMLSchema#int">7</o>
    </p>
  </s>

  <d parse="list">
    <o id="http://www.example.com/thing/2/" listId="_:b0" />
    <o id="http://www.example.com/thing/3/" />
  </d>

  <d parse="bag" id="_:b1">
    <o>1</o>
    <o>2</o>
    <o>3</o>
  </d>
  
</rdf>

The equivalent in RDF/XML is:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	 xmlns:ex="http://www.example.com/vocab#"
	 xmlns:html="http://www.w3.org/1999/xhtml">

  <rdf:Description rdf:about="http://www.example.com/thing/1/">
    <ex:plain>Plain Literal</ex:plain>
    <ex:lang xml:lang="en">English Literal</ex:lang>
    <ex:bag>
      <rdf:Bag>
	<rdf:li>1</rdf:li>
	<rdf:li>2</rdf:li>
	<rdf:li>3</rdf:li>
      </rdf:Bag>
    </ex:bag>
    <ex:list rdf:parseType="Collection">
      <rdf:Description rdf:about="http://www.example.com/thing/2/" />
      <rdf:Description rdf:about="http://www.example.com/thing/3/" />
    </ex:list>
    <ex:xml rdf:parseType="Literal">
      Below is:
      <html:div>Some <html:b>mixed</html:b> content.</html:div>
    </ex:xml>
    <ex:uri rdf:resource="http://www.example.com/thing/4/" />
    <ex:bnode rdf:nodeID="b2" />
  </rdf:Description>

  <ex:Type rdf:nodeID="b1">
    <ex:number rdf:datatype="http://www.w3.org/2001/XMLSchema#int">7</ex:number>
  </ex:Type>

</rdf:RDF>

2. Syntactic Constructs

TODO

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:

_:[a-zA-Z_][a-zA-Z0-9.\-_]*

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.

eg:

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

A blank literal can be represented as:

<tt:o/>

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.

eg:

<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.

eg:

<tt:o datatype="http://www.w3.org/2001/XMLSchema#dateTime">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.

eg:

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

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

TODO

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

TODO

2.4.2. Reification

TODO

3. Restrictions

TODO

3.1. Duplicate Subjects and Predicates

TODO

3.2. Well-formed Containers

TODO

3.3. Well-formed Collections

TODO

3.4. Well-formed Reified Statements

TODO

3.5. Well-formed XML literals

TODO

4. References

4.1. Normative References

[RDF]
"Resource Description Framework (RDF): Concepts and Abstract Syntax"
http://www.w3.org/TR/rdf-concepts/
[XML]
"Extensible Markup Language (XML) 1.0 (Fourth Edition)"
http://www.w3.org/TR/xml/
[XMLNAMES]
"Namespaces in XML 1.0 (Second Edition)"
http://www.w3.org/TR/REC-xml-names/
[XSDDATA]
"XML Schema Part 2: Datatypes Second Edition"
http://www.w3.org/TR/xmlschema-2/
[RDFURI]
http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference
[RFC3066]
"Tags for the Identification of Languages"
http://www.ietf.org/rfc/rfc3066
[RFC3987]
“Internationalized Resource Identifiers (IRIs)”
http://www.ietf.org/rfc/rfc3987

4.2. Informative References

[TURTLE]
"Turtle - Terse RDF Triple Language"
http://www.dajobe.org/2004/01/turtle/
[RDFXML]
"RDF/XML Syntax Specification (Revised)"
http://www.w3.org/TR/rdf-syntax-grammar/
[TRIX]
"RDF Triples in XML"
http://www.hpl.hp.com/techreports/2003/HPL-2003-268.html
[RXR]
"Modernising Semantic Web Markup"
http://www.idealliance.org/papers/dx_xmle04/papers/03-08-03/03-08-03.html
[XPATH]
"XML Path Language (XPath) Version 1.0"
http://www.w3.org/TR/xpath
[XSLT]
"XSL Transformations (XSLT)"
http://www.w3.org/TR/xslt