Parsing chunked XML into E4X

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Parsing chunked XML into E4X

Ben Bucksch
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.

and then

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...

dev-tech-xml mailing list
[hidden email]