From 8965bbe98b08b47370ea8ecca830707745ae383b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 5 Nov 2009 07:48:28 +0200 Subject: Handle loadGrammar failures --- examples/cxx/parser/performance/driver.cxx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'examples/cxx/parser') 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 # include # include + +# include +# include + #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 eh; + xml::sax::bits::error_handler_proxy 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::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); } else -- cgit v1.1