[xsd-users] Is it possible to know the progress of a parsing
process?
Boris Kolpackov
boris at codesynthesis.com
Wed Aug 5 09:03:25 EDT 2015
Hi Jaume,
Jaume Dominguez Faus <jaume.faus at vianova.no> writes:
> Can I have xerces (or xsd or some) telling me what is the current
> progress status of a file load (e.g. "5%", "17%", "99%", etc)?
There is no built-in functionality like this, but it is pretty
easy to implement yourself. The idea is to write your own
std::istream or xercesc::InputSource implementation that keeps
track of how many bytes have been read (which is a pretty close
approximation to how many have been parsed).
InputSource is actually easier to do. Take a look at libxsd/
xsd/cxx/xml/sax/std-input-source.hxx -- there you have everything
that you will need. In fact, you can derive from its
std_input_stream and override readBytes() to keep track of the
count. Then derive from std_input_source and return this custom
std_input_stream.
Once that is done, you can simply pass this input source to the
parsing function instead of std::istream, so your code will look
somethig along these lines:
std::ifstream ifs ("large.xml", ios::in | ios::binary | ios::ate);
size_t size (ifs.tellg ()); // Total size, to calculate %.
ifs.seekg (0, ios::beg);
progress_input_source is (ifs, size);
auto_ptr<root_t> r (root (is));
Boris
More information about the xsd-users
mailing list