[Expat-discuss] A Newbie question.

Josh Martin Josh.Martin@abq.sc.philips.com
Fri Jun 28 12:11:24 2002


> I have currently just started using Expat. I had a question as to whether it
> was possible to read the XML document that I recieve as an input stream from
> a client without having to write it to a file on the disk? If yes, how can I
> achieve that. A short example would be of great help.
> 
> Vijay Naidu
> System Analyst

The XML_Parse() function works on a buffer in memory, so writing the file to a 
disk and reading it back into a buffer would actually be doing more work than is 
required.  It would be possible to call XML_Parse() on each byte that you 
recieve from the input stream, if it streams one byte at a time, but that would 
be inefficient.  It would probably be better to buffer the input stream into an 
array as you're reading it, and then when the array gets full, parse that, and 
then clear the array and continue buffering.  Just make sure that you specify 
the length argument correctly in the call to XML_Parse(), and specify the 
isfinal argument to true when you are finished parsing the input stream.  
Remember that you will have to create a new parser object and start over again 
if you'll be parsing a series of XML documents from the stream rather than just 
one (although I think there's a function to reset the parser in expat 1.95.3).  
Let me know if you need any more information.

 - Josh Martin