[jdev] parsing xml (xmpp) with ruby

Dirk Meyer dmeyer at tzi.de
Mon Sep 29 11:03:12 CDT 2008


Eric Will wrote:
> There is no simple way to reason out when a stanza has ended. The
> way everyone seems to use is "use a SAX parser, then make a DOM out
> of that" which, to me, sucks. 

You do not need a real DOM with parent and stuff like that. I parse
the stanza from a SAX parser into a simple Python object for the
stanza.

> Plus, I'm using Ruby, so if I'm using a C parser like libxml to do
> the SAX, and then do all this mumbo jumbo in Ruby, it's going to
> cost me in terms of performance pretty badly.

The parsing is the hard part, creating some simple objects in Ruby
should be easy.

> My question is this: how often could this happen, TODAY? 

Well, maybe not today. I guess most clients create the stanza and send
it in one send() call. But if your code crashes somewhere on a bad
stanza, it is a perfect DOS on your server. But one read() could give
you more than one stanza. How do you plan to detect this?

> I think that's the client's problem.

The client works as expected, if your server can not handle this, your
server is broken.

> How bad could it be if I chose to simply ignore this and see what
> happens?

I'm one of 'everyone' your wrote about earlier: use SAX.


Dirk

-- 
"We're back to the times when men were men and wrote their own device 
 drivers"
     -- Linus Torvalds



More information about the JDev mailing list