diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-11-05 07:48:28 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-11-05 07:48:28 +0200 |
commit | 8965bbe98b08b47370ea8ecca830707745ae383b (patch) | |
tree | 4af8762062ff4badd9c68954e819487825c4c6f8 /examples/cxx/parser | |
parent | 9878dfe26a08ea5638c562c22c9becd11d462015 (diff) |
Handle loadGrammar failures
Diffstat (limited to 'examples/cxx/parser')
-rw-r--r-- | examples/cxx/parser/performance/driver.cxx | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/examples/cxx/parser/performance/driver.cxx b/examples/cxx/parser/performance/driver.cxx index 0fe2f02..da54aaa 100644 --- a/examples/cxx/parser/performance/driver.cxx +++ b/examples/cxx/parser/performance/driver.cxx @@ -19,6 +19,10 @@ # include <xercesc/validators/common/Grammar.hpp> # include <xercesc/util/PlatformUtils.hpp> # include <xercesc/util/XMLUni.hpp> + +# include <xsd/cxx/xml/sax/bits/error-handler-proxy.hxx> +# include <xsd/cxx/parser/error-handler.hxx> + #endif // No-op parser implementation. @@ -203,6 +207,9 @@ main (int argc, char* argv[]) // using namespace xercesc; + namespace xml = xsd::cxx::xml; + namespace parser = xsd::cxx::parser; + XMLPlatformUtils::Initialize (); { @@ -229,7 +236,24 @@ main (int argc, char* argv[]) parser->setFeature (XMLUni::fgXercesHandleMultipleImports, true); #endif - parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true); + // Initialize the schema cache. To detect schema errors we will + // need an error handler. + // + parser::error_handler<char> eh; + xml::sax::bits::error_handler_proxy<char> ehp (eh); + parser->setErrorHandler (&ehp); + + if (!parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true)) + { + // In Xerces-C++ grammar loading failure results in just a warning. + // Make it a fatal error. + // + eh.handle ("test.xsd", 0, 0, + parser::error_handler<char>::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); } else |