[xsd-users] dealing with xml written/read on-the-fly

Bill Pringlemeir bpringle at sympatico.ca
Tue Oct 20 15:38:55 EDT 2009


On 19 Oct 2009, cerion at kestrel.ws wrote:

> What I did before with Qt3 was fairly straightforward: SAX reader,
> callbacks on the end-tags to construct a DOM model.  The Qt SAX
> parser gives 'parse' and 'parseContinue' functions, which keep track
> of the file position and buffer the XML data until it's handed off
> via the end-tag callback.  All works well, and is simple.
> Unfortunately, there's just no binding, so updates to the XML
> protocol are horrible to maintain :-(

You can use a SAX parser (in Xerces as well) to parse available text.
When a known top level chunk tag is recognized, it can then be passed
to a normal XSD de-serializer.  The overhead for SAX parsing of tags
is fairly minimal.  Also, if you have a partial buffer, you would have
to keep the 'partial' XSD data model around to restart when more text
was found.  So having to keep the Valgrind text until SAX recognizes a
completion tag isn't really the worst overhead.  Having XSD (or
whatever solution) keep the entire DOM tree, a data model, and
possibly the text is definitely worse.

The only objection I see is that XSD should provide a mode to not
attempt to read further.  I think you could provide your own stream
and throw an exception if it reads beyond the known size.  That should
be a sanity check as opposed to a normal mode of operation.  You might
have to create some XML text that doesn't match the schema to test
this.

Fwiw,
Bill Pringlemeir.




More information about the xsd-users mailing list