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/tree/caching/driver.cxx | 24 ++++++++++++++++++++---- examples/cxx/tree/performance/parsing.cxx | 21 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'examples/cxx/tree') diff --git a/examples/cxx/tree/caching/driver.cxx b/examples/cxx/tree/caching/driver.cxx index 015606f..0a811e4 100644 --- a/examples/cxx/tree/caching/driver.cxx +++ b/examples/cxx/tree/caching/driver.cxx @@ -16,7 +16,6 @@ #include #include -#include #include #include "library.hxx" @@ -105,7 +104,17 @@ main (int argc, char* argv[]) // Initialize the schema cache. // - parser->loadGrammar ("library.xsd", Grammar::SchemaGrammarType, true); + if (!parser->loadGrammar ("library.xsd", Grammar::SchemaGrammarType, true)) + { + // In Xerces-C++ grammar loading failure results in just a warning. + // Make it a fatal error. + // + eh.handle ("library.xsd", 0, 0, + tree::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); conf->setParameter (XMLUni::fgXercesUseCachedGrammarInParse, true); // We will release the DOM document ourselves. @@ -133,7 +142,14 @@ main (int argc, char* argv[]) xml::dom::bits::error_handler_proxy ehp (eh); parser->setErrorHandler (&ehp); - parser->loadGrammar ("library.xsd", Grammar::SchemaGrammarType, true); + if (!parser->loadGrammar ("library.xsd", Grammar::SchemaGrammarType, true)) + { + eh.handle ("library.xsd", 0, 0, + tree::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); parser->setFeature (XMLUni::fgXercesUserAdoptsDOMDocument, true); @@ -161,7 +177,7 @@ main (int argc, char* argv[]) xml_schema::dom::auto_ptr doc (parser->parse (wrap)); #endif - eh.throw_if_failed > (); + eh.throw_if_failed (); // Parse DOM to the object model. // diff --git a/examples/cxx/tree/performance/parsing.cxx b/examples/cxx/tree/performance/parsing.cxx index 3997ea6..b7413a7 100644 --- a/examples/cxx/tree/performance/parsing.cxx +++ b/examples/cxx/tree/performance/parsing.cxx @@ -99,7 +99,17 @@ parsing (const char* file, unsigned long iter, bool validate) // If we are validating, pre-load and cache the schema. // - parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true); + 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, + xsd::cxx::tree::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); conf->setParameter (XMLUni::fgXercesUseCachedGrammarInParse, true); } else @@ -132,7 +142,14 @@ parsing (const char* file, unsigned long iter, bool validate) parser->setFeature (XMLUni::fgXercesSchema, true); parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); - parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true); + if (!parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true)) + { + eh.handle ("test.xsd", 0, 0, + xsd::cxx::tree::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); } else -- cgit v1.1