[xsd-users] dealing with xml written/read on-the-fly
boris at codesynthesis.com
Thu Oct 15 09:01:47 EDT 2009
Cerion Armour-Brown <cerion at kestrel.ws> writes:
> Unfortunately, the ordering of the elements is not as simple as in this
> example: during parsing we could receive one of a few different element
> types. I guess this approach would require me to take a look at the
> content of DocumentElement first, before allocating and intantiating a
> particular element type.
Yes, that's how you can handle this situation. There is an example
called multiroot that shows how to do this in the context of handling
XML documents with varying root elements.
> You say it will block if there's no data: when I try the examples out
> using files, an error is thrown when EOF is read instead of the expected
> xml. Hence my understanding that one would need to poll to make sure
> the read will succeed... Am I missing something?
If the stream ends with EOF then the parser assume there is no more
data available. And if the document is incomplete, then you will get
a parsing error. In your case, I guess, you will need to provide a
custom std::istream implementation (or xercesc::InputSource -- that
could actually be easier) that doesn't return on EOF but instead keeps
polling the file for more data (e.g., you could save the offset of the
last byte read, wait some time, re-open the file, seek to that saved
offset, and see if there is more data). I assume you will need to
implement this logic somewhere in the application in any case. With
this approach it will just be in the stream.
> Hmm. I'm wondering if I wouldn't be better of starting with the
> C++/Parser? Assuming I can make use of the auto-generated implementation,
> I could run the parser in a separate thread, leaving it in a blocking
> read, updating a shared memory model in post_ methods of document-level
> elements (and at the same time flagging the GUI thread that the model
> has been updated). What do you advise?
The auto-generated implementation is just a stub. You will still need to
provide your own classes that actually store the data as well as populate
them from the callbacks. You will also have the same issue with EOF as in
the C++/Tree model.
More information about the xsd-users