SAX is an event-driven parser for XML.

It sequentially reads the xml and generates special events. So, if you want to use SAX, you should implement the code to handle them. It’s quite different from the DOM model, where the whole xml is parsed and loaded in an tree. As you can see, the first approach is more difficult than the DOM one. Why we should use it? Depends. If you want to extract certain informations from a big file, probably you should choose a SAX implementation, in this way you can avoid the initial DOM loading overhead.

The Ruby XML Library

The Ruby core library has a built-in XML parser (both DOM and SAX) called REXML, but it’s terribly slow, it’s highly advisable to use libxml. It’s a binding to the popular library from Gnome and it was released as gem.