We’ve all been there. Gigantic XML file in need of parsing, regular DOM parsing exploderates RAM usage beyond any hope of completion, contemplating writing a SAX parser, and suicide.
Before you solve your XML parsing woes permanently, take a look at SAXMachine. It’s a Ruby DSL for SAX parsers. It’s built on top of Nokogiri, which is already stupid fast and easy, and it makes writing a SAX parser so much easier.
I’m not going to give you an example, the README from the above link does a good enough job explaining. For me, it took what had promised to be a multi-days long code spelunking odyssey and turned it into a few hour long errand. Bliss.
Just go read about it.