TriX Support for RDF.rb

TriX reader/writer for RDF.rb .

Gem Version Build Status Coverage Status Gitter chat


This is a [Ruby][] implementation of a TriX reader and writer for RDF.rb. TriX is an XML-based RDF serialization format developed by HP Labs and Nokia.


RDF::TriX parses TriX into statements or quads. It also serializes to TriX.

Install with gem install rdf-trix

  • 100% free and unencumbered public domain software.
  • Implements a complete parser and serializer for TriX.
  • Compatible with Ruby >= 3.0, and JRuby 9+.

Support for xml:base

The TriX reader natively supports xml:base in the top-level element without the need for an XSLT. This allows values of a uri element to be relative URIs and resolved against that base. The base can also be specified as an option to the reader.

For example:

<TriX xmlns=""
      <typedLiteral datatype="">32</typedLiteral>


Both reader and writer include provisional support for RDF-star.

Internally, an RDF::Statement is treated as another resource, along with RDF::URI and RDF::Node, which allows an RDF::Statement to have a #subject or #object which is also an RDF::Statement.

RDF-star is supported by allowing a triple element to contain another triple as either or both the subject or object.

Note that this requires the rdfstar option to be se.

Note: This feature is subject to change or elimination as the standards process progresses.

For example:

<TriX xmlns="">


Instantiate a reader from a local file:

repo = RDF::Repository.load("etc/doap.trix", :format => :trix)

Define @base and @prefix definitions, and use for serialization using :base_uri an :prefixes options.

Canonicalize and validate using :canonicalize and :validate options.

Write a repository to a file:"etc/test.trix") do |writer|
   writer << repo

Change Log

See Release Notes on GitHub




The recommended installation method is via RubyGems. To install the latest official release of the RDF::TriX gem, do:

% [sudo] gem install rdf-trix


To get a local working copy of the development repository, do:

% git clone git://

Alternatively, download the latest development version as a tarball as follows:

% wget

Mailing List



Refer to the accompanying CREDITS file.


This repository uses Git Flow to mange development and release activity. All submissions must be on a feature branch based on the develop branch to ease staging and integration.

  • Do your best to adhere to the existing coding conventions and idioms.
  • Don't use hard tabs, and don't leave trailing whitespace on any line. Before committing, run git diff --check to make sure of this.
  • Do document every method you add using [YARD][] annotations. Read the [tutorial][YARD-GS] or just look at the existing code for examples.
  • Don't touch the .gemspec or VERSION files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.
  • Don't touch the AUTHORS file. If your contributions are significant enough, be assured we will eventually add you in there.
  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you, which you will be asked to agree to on the first commit to a repo within the organization. Note that the agreement applies to all repos in the Ruby RDF organization.


This is free and unencumbered public domain software. For more information, see or the accompanying UNLICENSE file.