Xml parser using non-blocking input

brunodecarvalho kindernade at gmail.com
Mon Aug 23 19:39:02 EDT 2010


Trevor,


I've recently did some xml parsing with Netty. 

I did, however, took the naive (lazy) approach of incrementally storing the
contents of the result in a ChannelBuffer and, upon its completion, feed it
to the XmlPullParser. I'll eventually go over this* when I get the chance,
but this seems like a nice opportunity to exchange some ideas.

* or not, since these documents are small and it's not too uncommon to need
the document as a String as well (logging requirements, go figure...).

Personally, I'd go with XPP over SAX (here's a nice explanation on why SAX
is "ass backwards": http://www.bearcave.com/software/java/xml/xmlpull.html).
XPP parsers are way simpler to write.

Problem is XPP is great to deal with InputStreams. When you try to advance
the "cursor", if there is no data available, the parsing thread will simply
block until data becomes available.

With Netty, your handlers get their messageReceived() method called with a
bunch of bytes, which means that if you either take the lazy approach of
buffering all the bytes of the XML document and then creating a new
ChannelBufferInputStream(yourbuffer) or you'll need another thread to be
parsing the XML (read "blocking until data was available and advancing the
XPP cursor").

No idea on how this would look with a SAX parser, though... Maybe it fits
better than with XPP!


Cheers,
  Bruno
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Xml-parser-using-non-blocking-input-tp5453173p5454737.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list