Parsing chunked XML into E4X

3 views
Skip to first unread message

Ben Bucksch

unread,
Feb 22, 2011, 10:32:57 AM2/22/11
to
My situation is the following:

* Implementing XMPP/Jabber
* in privileged JS (chrome)
* using nsISocketTransport , i.e. raw TCP sockets
* using E4X to access the XML


Now, the problem is that the server or Mozilla might send an XML
"stanza" (= XML subtree) in several chucks into my onDataAvailable(). I
get e.g.

"<foo><bar>dfgdh</bar>"
and then
"<bar>tzzubn</bar></foo>"

If I parse the first using E4X, it throws "tag not closed" or similar.
Which is correct, but poses my problem.

I see 2 solutions:

* If I get such a "tag not closed" error, I save the chuck as
string, and append the next chunk once I receive it, and then try
to parse again. Of course, that might still not be the full
content, so I have to wait basically infinitely. And that's where
my problem is: If I have a genuine parse error, e.g. due to a
server error, missing content etc., my connection hangs. I don't
want that, obviously.
* Using a SAX parser. Unfortunately, that's quite complicated, and I
definitely don't want to use that on the app / XMPP XML layer, so
I'd have to translate SAX into E4X, and I don't know how to do
that easily.

Does somebody have another idea?
(Please only ideas within the above circumstances - they are a given.)

If nobody has a better idea, I'll probably use Option 1, and hope for
the best...

Ben

Reply all
Reply to author
Forward
0 new messages