diff options
-rw-r--r-- | examples/cxx/parser/performance/driver.cxx | 26 | ||||
-rw-r--r-- | examples/cxx/tree/caching/driver.cxx | 24 | ||||
-rw-r--r-- | examples/cxx/tree/performance/parsing.cxx | 21 | ||||
-rw-r--r-- | libxsd/xsd/cxx/parser/error-handler.hxx | 2 | ||||
-rw-r--r-- | libxsd/xsd/cxx/tree/error-handler.hxx | 2 | ||||
-rw-r--r-- | libxsd/xsd/cxx/xml/error-handler.hxx | 1 |
6 files changed, 66 insertions, 10 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 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 <xsd/cxx/xml/dom/bits/error-handler-proxy.hxx> #include <xsd/cxx/xml/sax/std-input-source.hxx> -#include <xsd/cxx/tree/exceptions.hxx> #include <xsd/cxx/tree/error-handler.hxx> #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<char>::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed<xml_schema::parsing> (); 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<char> 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<char>::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed<xml_schema::parsing> (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); parser->setFeature (XMLUni::fgXercesUserAdoptsDOMDocument, true); @@ -161,7 +177,7 @@ main (int argc, char* argv[]) xml_schema::dom::auto_ptr<DOMDocument> doc (parser->parse (wrap)); #endif - eh.throw_if_failed<tree::parsing<char> > (); + eh.throw_if_failed<xml_schema::parsing> (); // 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<char>::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed<xml_schema::parsing> (); 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<char>::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed<xml_schema::parsing> (); parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); } else diff --git a/libxsd/xsd/cxx/parser/error-handler.hxx b/libxsd/xsd/cxx/parser/error-handler.hxx index b44974f..925ebc8 100644 --- a/libxsd/xsd/cxx/parser/error-handler.hxx +++ b/libxsd/xsd/cxx/parser/error-handler.hxx @@ -19,9 +19,9 @@ namespace xsd template <typename C> class error_handler: public xml::error_handler<C> { + public: typedef typename xml::error_handler<C>::severity severity; - public: error_handler () : failed_ (false) { diff --git a/libxsd/xsd/cxx/tree/error-handler.hxx b/libxsd/xsd/cxx/tree/error-handler.hxx index 13e41a5..5de4415 100644 --- a/libxsd/xsd/cxx/tree/error-handler.hxx +++ b/libxsd/xsd/cxx/tree/error-handler.hxx @@ -19,9 +19,9 @@ namespace xsd template <typename C> class error_handler: public xml::error_handler<C> { + public: typedef typename xml::error_handler<C>::severity severity; - public: error_handler () : failed_ (false) { diff --git a/libxsd/xsd/cxx/xml/error-handler.hxx b/libxsd/xsd/cxx/xml/error-handler.hxx index 76482b7..a618ac3 100644 --- a/libxsd/xsd/cxx/xml/error-handler.hxx +++ b/libxsd/xsd/cxx/xml/error-handler.hxx @@ -57,4 +57,3 @@ namespace xsd } #endif // XSD_CXX_XML_ERROR_HANDLER_HXX - |