Skip to content

lutaml/oasis-etm

Repository files navigation

OASIS Exchange Table Model (ETM) Parser

Purpose

The OASIS ETM format is a simple XML format for representing tables for exchange. It is used in the DocBook and NISO JATS standards.

This library provides a Ruby implementation of the OASIS Technical Resolution TR 9503:1995.

Features

  • Full implementation of the OASIS Exchange Table Model TR 9503:1995

  • Intentionally excludes CALS table features not part of the Exchange subset (like tfoot)

  • XML serialization and deserialization

  • Validation of attribute values

  • Support for all Exchange Table Model elements:

    • table

    • tgroup

    • colspec

    • thead

    • tbody

    • row

    • entry

Installation

Add this line to your application’s Gemfile:

gem 'oasis-etm'

And then execute:

bundle install

Or install it yourself as:

gem install oasis-etm

Usage

Basic example

require 'oasis-etm'

# Parse an ETM XML file
table = Oasis::Etm::Table.from_xml(File.read('table.xml'))

# Access table attributes
puts table.frame
puts table.colsep
puts table.rowsep

# Access table content
table.tgroups.each do |tgroup|
  tgroup.colspecs.each do |colspec|
    puts "Column #{colspec.colnum}: #{colspec.colwidth}"
  end
end

# Create a new table
table = Oasis::Etm::Table.new(
  frame: 'all',
  colsep: 1,
  rowsep: 1,
  tgroups: [
    Oasis::Etm::Tgroup.new(
      cols: 3,
      colspecs: [
        Oasis::Etm::Colspec.new(colnum: 1, colwidth: '1*'),
        Oasis::Etm::Colspec.new(colnum: 2, colwidth: '2*'),
        Oasis::Etm::Colspec.new(colnum: 3, colwidth: '1*')
      ]
    )
  ]
)

# Convert to XML
xml = table.to_xml

XML schema

The OASIS ETM format follows this basic structure:

<table frame="all" colsep="1" rowsep="1">
  <title>Sample Table</title>
  <tgroup cols="3">
    <colspec colnum="1" colwidth="1*"/>
    <colspec colnum="2" colwidth="2*"/>
    <colspec colnum="3" colwidth="1*"/>
    <thead>
      <row>
        <entry>Header 1</entry>
        <entry>Header 2</entry>
        <entry>Header 3</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Cell 1</entry>
        <entry>Cell 2</entry>
        <entry>Cell 3</entry>
      </row>
    </tbody>
  </tgroup>
</table>

Round-Trip Conversion Tests

The round-trip tests in spec/oasis/etm_spec.rb verify that XML files can be parsed into Ruby objects and then serialized back to XML without loss of semantic content.

Note
These tests use the Canon gem for XML comparison with the spec_friendly profile, which ignores non-semantic differences like attribute ordering and formatting.

Purpose

Round-trip conversion testing ensures that:

  • The parser correctly interprets all supported XML elements and attributes

  • The serializer correctly produces XML that preserves semantic meaning

  • The model accurately represents the Exchange Table Model structure

Test Fixtures and Sources

The round-trip tests use real-world XML files from various standards:

Fixture Source Purpose

spec/fixtures/native/docbook_example.xml

DocBook Table Specification

Tests native ETM format (no namespace prefix)

spec/fixtures/niso-jats/niso-jats-table-wrap.xml

NISO JATS Tag Library

Tests ETM with standard OASIS namespace (http://docs.oasis-open.org/ns/oasis-exchange/table)

spec/fixtures/isosts/isosts_tables.cals.{nn}.xml

ISO ISOSTS Test Suite

Tests ETM with alternative namespace URIs and CALS extensions

Fixture Oddities

The test fixtures contain elements and attributes that are not part of the Exchange Table Model specification but appear in real-world documents. The round-trip tests handle these as follows:

Some fixtures contain elements from other namespaces that the model does not support. These are removed before parsing to focus on Exchange Table Model compatibility:

Table 1. Foreign Elements (Removed Before Parsing)
Element Fixture

<xref> (NISO JATS cross-references)

niso-jats-table-wrap.xml

<para> (DocBook paragraph)

docbook_example.xml

<bold> (DocBook inline formatting)

isosts_tables.cals.02.xml

The Exchange Table Model has evolved over time, resulting in multiple namespace URIs that refer to the same schema:

Table 2. Namespace Variants
Namespace URI Used By

http://docs.oasis-open.org/ns/oasis-exchange/table

Canonical OASIS Exchange Table namespace

urn:oasis:names:tc:xml:table

ISO ISOSTS format

-//OASIS//DTD XML Exchange Table Model 19990315//EN

Legacy FPI (Formal Public Identifier) - used as namespace URI in older documents

The model accepts all three namespace variants via uri_aliases for parsing. When serializing, the model uses the canonical namespace URI for output.

The Exchange Table Model predates XML Schema and uses SGML-influenced attribute values:

Table 3. Attribute Value Formats
Values Example

Integers (XML Schema)

colsep="1" rowsep="1"

Legacy strings (SGML)

colsep="yes" rowsep="no"

The model accepts both integer (0, 1) and string ("yes", "no") values for colsep, rowsep, and pgwide attributes to ensure backward compatibility with legacy documents.

Why These Tests Matter

Round-trip tests catch regressions that might otherwise go unnoticed:

  • A missing attribute mapping would cause data loss on serialization

  • An incorrect type coercion would change attribute values

  • Namespace handling bugs would produce invalid XML

  • Changes to element ordering could break downstream consumers

By testing with real-world fixtures from established standards, we ensure compatibility with the broader XML table ecosystem.

Contributing

Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

  1. Fork it

  2. Create your feature branch (git checkout -b my-new-feature)

  3. Commit your changes (git commit -am 'Add some feature')

  4. Push to the branch (git push origin my-new-feature)

  5. Create new Pull Request

This project is licensed under the BSD 2-clause License. See the LICENSE.md file for details.

Copyright Ribose.

About

Ruby library for OASIS Exchange Table Model (a subset of CALS table)

Resources

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors