From: Robert Klemme Date: 2008-09-28T06:39:25+09:00 Subject: Re: parsing xml (xmpp) with ruby On 27.09.2008 21:27, Eric Will wrote: > Another option is to use REXML's stream parsing. I don't really like > this idea. It seems the only benefit of using SAX(ish) parsing is when > you're dealing with huge documents that you don't want to load into > memory. This isn't the case. I get maybe 5-10 objects per parse. Most > of the people I've talked to in XMPP insist on using SAX (or something > like it, such as REXML's stream parsing). The other reason I don't > like REXML's stream parsing (or libxml's SAX) is because I have to > provide a class instance for it to use for the event-parsing, and this > class has to be a giant state machine, which seems wrong to me. I > don't want to have to write a complicated class to, in effect, parse > the XML myself when the XML parser should be doing this for me. Well, this is not true. You can have multiple classes cooperating in doing XML stream parsing. You need one instance for receiving the events but that can delegate to any number of other instances. A scheme I usually use is to have a class per element type and the front end instance keeps a stack of those. Typically XML is parsed to instantiate classes of a particular object model that is built do implement the business logic (in your case message exchange). It is a waste of resources to create an XML DOM and then traverse it in order to transform it into other objects. Also, not all input data is needed in every case. That's why stream parsing has serious advantages over DOM parsing. OTOH, if you can do all your processing efficiently on the DOM then maybe that is a better way. In your situation I would still choose the stream approach because it also better fits the way the data is provided. My 0.02 EUR robert