[cxml-devel] parsing from a http stream (no EOF at the end)

David Lichteblau david at lichteblau.com
Mon Oct 3 17:11:00 UTC 2011


Quoting Attila Lendvai (attila.lendvai at gmail.com):
> >> could someone comment on this? was cxml ever meant to support such
> >> use-case, just noone really needed it yet?
> >
> > What use case exactly? When and how should the parser "stop"? (keep in
> > mind that the "last closing tag" does not neccessarily signal the end
> > of a well-formed xml document)
> 
> 
> i see, thanks. for some reason i assumed that an xml document may only
> have one toplevel element.

Only one _element_, but comments, processing instructions, and space can
follow, and need to be parsed.

> the use-case is simple xml messaging over http.

There is code in cl-xmpp which deals with a similar situation: XMPP
opens something that looks like an XML document using a start tag, but
then the actual messages are the children of this "infinite" document
element.  cl-xmpp solves it using cxml, IIRC using klacks to read the
individual child elements.  Don't know if that helps you, but perhaps
you might want to take a look (start reading code at READ-STANZA).

No matter whether you're using klacks or sax, in general you could just
stop parsing when you're done.  In the case of klacks, you simply avoid
doing further klacks calls read event events.  In the case of SAX, you
need to define a method on the sax:end-element generic function, and
perform a non-local transfer of control out of the parser.

If you want to read more data from the stream afterwards, one important
trick while doing the above is the :speed 1 setting that cl-xmpp uses.
It sets cxml's buffer to a single character, effectively disabling that
buffer.  The xstream API that deals with these details is undocumented,
but rather straightforward.


d.




More information about the cxml-devel mailing list