Skip to content

Latest commit

 

History

History
166 lines (127 loc) · 3.87 KB

README.adoc

File metadata and controls

166 lines (127 loc) · 3.87 KB

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>

Development

Test files

spec/fixtures/native/docbook_example.xml

https://tdg.docbook.org/tdg/4.5/table

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

https://jats.nlm.nih.gov/options/OASIS/tag-library/19990315/element/oasis-table.html This is to test the OASIS exchange table model when it is namespaced from another location.

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

Tables extracted from https://www.iso.org/schema/isosts/cals/test/isosts_tables.cals.xml. This is to test the OASIS exchange table model when it is namespaced from another location.

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.