[jdev] parsing xml (xmpp) with ruby

Stephan Maka stephan at spaceboyz.net
Tue Sep 30 19:39:31 CDT 2008


Eric Will wrote:
> It doesn't complain about a partial file. If I pass it a partial
> stanza, with say the end tag only halfway finished, like "</prese" it
> raises an exception. The exception tells me nothing that I can use to
> isolate the incomplete stanza and save it to be appended onto later.
> 
> I feed it data that I pull out of the socket's read() method. It has
> listeners for start tags, text, and end tags. The method that handles
> the start tag sets everything up, and starts to build a tree. The end
> tag method passes the tree to a handler function.

If you stick to REXML (which you shouldn't if you aim for performance)
you should read XMPP4R's streamparser.rb. The usage of REXML's SAX2
parser is really straight-forward there.

If you're using libxml-ruby then I recognize your problem. The key is
using the parser in "push mode". Take a look at the last patch I sent to
their list.

Don't explain that much, but share your code.


Stephan



More information about the JDev mailing list