Forum: Ruby generic XML importer/exporter for ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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
format:

  <root>
    <firstelement>
      <secondelement firstattr='1'>
        some value
      </secondelement>
      <secondelement firstattr='2'>
        some other value
      </secondelement>
    </firstelement>
  </root>

all you have to write is this:

  require 'xmlcodec'

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

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

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

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

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

http://www.pedrocr.net/ruby/

and is LGPL licensed.

Greetings,

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