[jdev] Re: Re: Re: Parsing XMPP/Jabber protocol
Heiner Wolf
wolf at bluehands.de
Mon Jan 3 07:13:54 CST 2005
Hi,
> String s1 = "<?xml version=\"1.0\"?><str";
> String s2 = "eam><element>qwe</element></stream>";
I wonder who would ever be interested in getting notification of a
partial <stream> tag. This is a weird case and I suppose applications
have no problem waiting for the "eam>".
The interesting case is to get notifications of the level 1 sub tags of
the document. In Jabber terminology these are the stanzas <message/>,
<presence/>, and <iq/>. You will definitely get endElement() for
<element/>, as you would expect from SAX. And this is all you need.
>but
>
> to get endDocument() stream.close() is necessary
While implementing a Jabber client, endDocument() is just not relevant.
If you ever get endDocument() then close the connection from your side.
If you do not get it, then everyhing is fine. endDocument() is nothing
to worry about.
What worries me much more is that all developers use SAX parsers and
anyone has to re-create the XML structure from those
startElement/stopElement sequences. I wonder why there is no better API
than the Simple API for XML. I guess everyone who implemented the
protocol, had to re-create the XML fragments from
startElement/stopElement sequences. For streaming XML SAX is not enough.
Developers would need a bit more, a mixture of DOM and SAX. A kind of
"Fragment API for XML" that stream-parses XML like SAX, but returns
fragments as DOM like data structures.
Instead of the startElement() and stopElement() the application should
have a callback OnElement(XMLNode node) that delivers full nodes
including children. For Jabber OnElement does something like:
if (node.depth() == 1)
// handle stanza
else
// let any level except depth == 1 pass untouched
hw
--
Dr. Klaus H. Wolf
bluehands GmbH & Co.mmunication KG
http://www.bluehands.de/people/hw
+49 (0721) 16108 75
--
Jabber enabled Virtual Presence on the Web: http://www.lluna.de/
Open Source Future History: http://www.galactic-developments.com/
>-----Original Message-----
>From: jdev-bounces at jabber.org [mailto:jdev-bounces at jabber.org]On Behalf
>Of Maxym Gorodetskyy
>Sent: Sunday, January 02, 2005 9:40 PM
>To: jdev at jabber.org
>Subject: [jdev] Re: Re: Re: Parsing XMPP/Jabber protocol
>
>
>Cathayan wrote:
>
>> if i don't misunderstand it, java xerces2's SAX parser can deal with
>> delayed inputstream very well, i just tried it and get the jabber
>> server's returned id correctly, no tricks needed again.
>>
>> see it:
>>
>> http://xml.apache.org/xerces2-j/samples-socket.html#DelayedInput
>>
>>
>
>Yes, yes, yes, you did not!
>
> Socket clientConnection = new Socket();
> clientConnection.connect(new
>InetSocketAddress("127.0.0.1", 2000));
> OutputStream stream = clientConnection.getOutputStream();
> String s1 = "<?xml version=\"1.0\"?><str";
> String s2 = "eam><element>qwe</element></stream>";
> stream.write(s1.getBytes());
> stream.flush();
> Thread.sleep(1000);
> stream.write(s2.getBytes());
> stream.flush();
>
> I am getting correctly
> startDocument()
> startElement() for stream
> startElement() for element
> endElement() for element
> endElement() for stream
>
>but
>
> to get endDocument() stream.close() is necessary
>
>I am not sure what standard java 1.4 SAX parser will do.
>
>
>--
>Best regards
>Maxym Gorodetskyy
>
>
>_______________________________________________
>jdev mailing list
>jdev at jabber.org
>http://mail.jabber.org/mailman/listinfo/jdev
>
More information about the JDev
mailing list