[jdev] Re: Splitting the stream

Alexander Gnauck gnauck at ag-software.de
Wed Nov 1 11:12:15 CST 2006

Matthias Wimmer wrote:
> Michal 'vorner' Vaner schrieb:
>> And, if I have these split things and insert them between the stream
>> header I got in the beginning and an corresponding stream end, can I
>> parse it using DOM parser for each separate stanza?
> But that is something I would not do. It requires you to parse the
> complete data twice. I'd just use a SAX parser for the complete stream.
> And with the SAX-events you can generate DOM-Nodes in a DOM-Document.
> E.g. you could have one document for the stream, generated inside the
> SAX-Events. When you notice, that a stanza has been completed, you can
> call the handler for the stanza with the handle/pointer/... to that
> element in the document. After the handler returned/the stanza has been
> processed, you can just remove that stanza root element from the DOM
> document again.

i agree with Matthias.
The technique you should use also depends on the programming language 
and the XML libraries you use. From my experience "SAX like" techniques 
works very well for XMPP streams.
==> Parsing the stream with Sax and build your Dom or stanzas from the 
sax callbacks.

As Matthias already mentioned some developers see the complete stream 
(including the header) as one XML Document, others use the header only 
to grab the correct namespace and see each stanza as a new DOM which is 
not in the context of the stream header.

All techniques have their pros and cons which also strongly depends on 
your programming language and XML libraries.

It also depends on your project and requirements. It's a big difference 
if you need a light and really fast implementation for a embedded 
device, or if you don't care about speed but want a complete namespace 
correct and validating implementation.


More information about the JDev mailing list