[xsd-users] dealing with xml written/read on-the-fly
Boris Kolpackov
boris at codesynthesis.com
Tue Oct 20 10:08:36 EDT 2009
Hi Cerion,
Cerion Armour-Brown <cerion at kestrel.ws> writes:
> I would _really_ have liked to use a file for debugging purposes: I
> don't trust the XML source (Valgrind) not to mess things up, and I
> wanted to allow users of my program to send me the XML file so I could
> reproduce the error.
You could "tee" the data to a file that the user could send you
for debugging. It should also be pretty simple to "replay" such
a file to a socket or pipe.
I think I also figured out how to support the file approach. Your
custom stream implementation would assume all EOFs are fake until
notified otherwise. The SAX parser that builds the DOM chunks
keeps track of the document depth. So you need to add a test in
the endElement() function (after the depth is decreased, see
parser.cxx in the example) for when you reach depth_ == 0. This
means that the end tag has been seen. At this point you notify the
stream to treat all further EOF as real.
> 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 :-(
Expat supports this API (parse/parseContinue) but it can only be used
with C++/Parser in XSD. In XSD/e (XML data binding for mobile/embedded
systems), however, there is the C++/Hybrid mapping which is basically
an object model on top of the C++/Parser mapping. It also works with
Expat (which is part of the XSD/e runtime library). So if you really
want this parse/parseContinue approach then you can try C++/Hybrid.
It supports partially event-driven, partially in-memory processing
which will allow you to build and display the object model chunk by
chunk (the streaming example for C++/Tree was in fact inspired by
this). See the streaming example in the examples/cxx/hybrid/ directory
of the XSD/e distribution for more information.
Boris
More information about the xsd-users
mailing list