Tuesday, October 2, 2007

Getting libxml-ruby working under Windows

Unfortunately the 'gem install libxml-ruby' doesn't seem to work under Windows because of missing dependencies. However, the following web site has a pre-compiled Windows binary:

http://cfis.savagexi.com/articles/2007/02/09/ruby-libxml-and-windows
http://cfis.savagexi.com/files/libxml_so.so

Following is the process I went through to get it working.

Save the libxml_so.so file (which is essentially a windows DLL) into the ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml directory. This installs the low-level libxml library wrapper which can be accessed by

require 'xml/libxml_so'

This library defines all of the basic objects and methods needed for libxml.

However, there is also the libxml.rb file. This file can be installed to ruby\lib\ruby\1.8\xml directory. This file itself requires the 'xml/libxml_so', and it can in turn be accessed by

require 'xml/libxml'

The libxml.rb adds some aliases and convenience methods such as enumerators and array accessors [] to the API already defined by the 'xml/libxml_so' library. This is why the classes imported from the 'xml/libxml_so' behave slightly differently from the classes imported from the 'xml/libxml'. This was a bit of a stumbling point until I realized what was happening. Most libraries expect the 'xml/libxml' and not the 'xml/libxml_so'.


You can get the libxml.rb file by downloading the tarball from http://rubyforge.org/frs/download.php/15237/libxml-ruby-0.3.8.4.tar.gz. Or, if you have attempted the

> gem install libxml-ruby --version 0.3.8.4

Even if it fails, the libxml.rb file is in the ruby\lib\ruby\gems\1.8\gems\libxml-ruby-0.3.8.4\ext\xml directory.

The libxml.rb file should then be copied into the ruby\lib\ruby\1.8\xml directory.

Hopefully this will help anyone trying to get libxml working under Windows.

0 comments: