It’s just data

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.


Patch for libxml2’s Ruby binding

Any chance that it will continue to get that TLC from you?  I’d be willing to vote to have you canonized for doing it.

One of my few disappointments with Ruby is the lack of decent libxml bindings, but I continue to find reasons not to return to using the C side of my brain.

Posted by kellan at

Patch for libxml2’s Ruby binding

I’d love nothing more than to find somebody to commit my patches and somebody (else?) to provide test cases.

Posted by Sam Ruby at

Patch for libxml2’s Ruby binding

pity that it still doesn’t compile on OS X

Posted by Julik at

While you were out

I managed to recover my laptop battery within two weeks of good charging practices and despite its old age. It’s an ASUS, just in case you were interested, and it’s been serving me well since the last quarter of 2001 when I bought it. As...

Excerpt from The Long Dark Tea-time of the Blog at

Patch for libxml2’s Ruby binding

Sam,

As you may know I recently volunteered to help look after Libxml. So far we’ve not really gotten started, but I’ve been gathering up patches and so on (thanks :)). I’ve proposed that we start off by fixing these code-rot issues and getting a release out the door, so assuming that goes ahead I think I’ll probably be the one to get your patches in.

If I have my way we’ll have a ‘ground zero’ release sometime in January, but that’s just me...

Thanks again!

Posted by Ross Bamford at

Add your comment