[xsd-users] Stream parsing genaral question

Boris Kolpackov boris at codesynthesis.com
Mon Jan 31 10:32:48 EST 2011


Hi Anatoly,

Anatoly Gutnick <anatolyg at gmail.com> writes:

> Can it work in the following way:
> 
> -  application read XML data buffers from socket (for example) in 2 chunks:
> 
> First chunck is:
> 
> <contact>
>   <name>John Doe</name>
>   <e
> 
>  Second chunck:
> 
> mail>j at doe.com</email>
>   <phone>555 12345</phone>
> </contact>
> 
> -  Is it possible to put chunck by chunck to the XML parser (NOT full XML
> buffer) and to get data parsed.

Yes, in the example above you can feed the parser the first chunk and
have the 'name' callback called.


> If so then where i can see such example?

There is no example that shows exactly that, but here are the general
steps you will need to take:

1. Implement the input stream to read from the socket. You can choose
   from several interfaces. For Xerces-C++ as the underlying parser,
   you can use std::istream or xercesc::InputSource. InputSource
   is probably the easier option to implement. For Expat you can
   use std::istream or pass the chunks directly to the parser (see
   the documentation for the Expat's document parser in the Getting
   Started Guide.

2. Pass this input stream (or chunks) to the parse() function.

Note that you can also do streaming with the C++/Tree mapping with
a bit of work. See the 'streaming' example in the examples/cxx/tree/
directory of the XSD distribution.

Boris



More information about the xsd-users mailing list