Patch for libxml2's Ruby binding
I mentioned previously that libxml2 had a habit of writing to STDERR. With the Python bindings, this can be mitigated by the use of an error handler global to the library. The steps below describe how to add equivalent functionality to Ruby’s bindings.
Preparations
Standard stuff. Install prereqs, checkout source.
sudo apt-get install build-essential libxml2-dev libxslt1-dev zlib1g-dev cvs ruby ruby1.8-dev rake cvs -d :pserver:anonymous@rubyforge.org:/var/cvs/xml-tools login cvs -d :pserver:anonymous@rubyforge.org:/var/cvs/xml-tools checkout libxml-ruby cd libxml-ruby
building
It looks like the bindings haven’t been updated to support gcc 4.0, hence the need for a patch...
wget http://intertwingly.net/stories/2005/11/05/rubyxml.tgz tar xzf rubyxml.tgz patch < rubyxml_gcc40.patch ruby extconf.rb make sudo make install
testing
Not seeing any convenient way to run the tests, I create a Rakefile. Apparently, the original scaffolding automatically took care of a number of requires? Added in via a patch. Oh, and it seems that those files aren’t Outdated after all.
patch -p 0 < rubyxml_tests.patch cp Outdated/*.xml . rake
Here’s the results. Not perfect, but sufficient for my needs for the moment.
coding
Add the desired functionality as well as a test.
patch < registerErrorHandler.patch make sudo make install mv test_registerErrorHandler.rb tests rake
Note that there is no need to pass a context parameter to registerErrorHandler as this is all taken care of by closures.
conclusion
Clearly the Ruby bindings to libxml2 need a little TLC. I’ve worked with a number of C Language APIs, and I Ruby’s has been the easiest to get started with.
libxml2 is among the fastest and most spec compliant implementations out there. While its current API is a bit low level, clearly it has all the necessary function to support the layering on of a higher level API.
Meanwhile, I’ve found that submitting a patch is an effective way to determine the health of the community around a project.