Ruby and XML

By reeset / On / In Programming

I’ve been doing quite a bit of programming of late in Ruby and I have to say, I’m really disappointed in Ruby’s XML support.  REXML — the built-in Ruby library, well, stinks.  I’ve been trying to use it to parse some simply MarcXML records, and what I’ve finding is that its taking the process ~0.4-0.5 seconds to load the file.  These are small files.  Then processing — use XPATH and you pay dearly, use the more well documented convenience functions, again, you pay dearly. 

Anyway, the point of this was I was looking through some code and trying to figure out why some portions of my rails app was doggy.  From my investigation, I found two doggy point — one the result of a misunderstanding as to the best way to do an operation in ruby — the second, the REXML processor.  So what to do?  Well, I’m going the libxml2 way.  There is a ruby gem that allows you to work directly with the libxml2 library and problem solved.  In testing today, I found that this library was 30-50% faster in nearly all cases, with speed performance increasing the larger the document that was loaded.  I’m hoping that once I integrate the use of libxml into my app and gut the REXML code that I’ll continue to see these speed improvements.


One thought on “Ruby and XML