Forum: Ruby generic XML importer/exporter for ruby

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pedro Côrte-Real (Guest)
on 2006-05-12 15:31
(Received via mailing list)
I've written a generic importer/exporter between XML and ruby objects.
What this means is that to generate an importer/exporter for this

      <secondelement firstattr='1'>
        some value
      <secondelement firstattr='2'>
        some other value

all you have to write is this:

  require 'xmlcodec'

  class Root < XMLCodec::XMLElement
    elname 'root'
    xmlsubel :firstelement

  class FirstElement < XMLCodec::XMLElement
    elname 'firstelement'
    xmlsubel_mult :secondelement

  class SecondElement < XMLCodec::XMLElement
    elname 'secondelement'
    xmlattr :firstattr

This will create some ruby objects with methods to set the subelements
and the attributes and to import/export XML.

Besides being able to import/export the REXML DOM it can also create
XML text itself in one go (which is faster and uses less memory).

It also supports a "partial_export" mode where you can export a big
XML file by normally creating the elements but then exporting as you
create the tree and then deleting the element so that GC can reclaim
the object.

For the importing it has a XMLStreamObjectParser which is a stream
parser whose events are whole elements instead of start/end tags.

I've created and parsed 100MB files with these API's with minimal memory

I've done this to process EAD XML files so an example of the use of
the library is "eadcodec", the EAD importer/exporter.

Suggestions about the code and API are very welcome.
Opinions/Suggestions about the name "xmlcodec" would be great to.

The code can be found in

and is LGPL licensed.


Pedro Côrte-Real.
This topic is locked and can not be replied to.