Re: [xml] Need example / help for using SAX parsing on IO stream (socket)
- From: Daniel Veillard <veillard redhat com>
- To: Chris Hesterman <hester nortel com>
- Cc: xml gnome org
- Subject: Re: [xml] Need example / help for using SAX parsing on IO stream (socket)
- Date: Wed, 13 Jul 2005 12:29:18 -0400
On Wed, Jul 13, 2005 at 11:43:12AM -0400, Chris Hesterman wrote:
I've been searching for documentation and / or code examples for using
the SAX parser in libxml2 to parse an input stream (XML messages being
received over a socket). I have played around a lot, but need some
guidance on how to use the IO methods and SAX....
Here are the goals I'm trying to acheive with this code:
1. parse an input stream of messages (from a socket connection)
the parser can't split the messages for you, you will have to
take control over the socket then. As I said repeatedly stacking multiple
XML document within a single stream is a design mistake error.
2. parse "on the fly" (i.e. don't require that the entire message has
been collected before parsing). I assume this implies using SAX and I/O
No. This implies using a Push mode.
3. keep memory requirements low by not creating a tree (i.e. use SAX).
or the XML reader but this may not be possible in push mode.
4. account for the retrieval of a message requiring multiple reads from
the socket (i.e. the message length is larger than the socket's buffer).
Since you're packing multiple message on a single socket you will need
to do the reads. Then push the data on the parser context
My guess as to how to go about this is to use the following methods, but
I need some verification that I'm using the right ones, and an example
of how to piece it all together: For now I just want to get the basics
working, and have a print out when the start of a message ("<rpc
message-id="123">") or the end of a message ("</rpc>") is detected, and
I'll build from there...
I don't have time to read and review other people code, so read mine:
see xmllint.c around line 2107
You need to use
xmlCreatePushParserCtxt() passing your SAX block and user data
xmlParseChunk() until all document input have been consumed.
Daniel Veillard | Red Hat Desktop team http://redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
] [Thread Prev