diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
commit | 8286ac511144e4f17d34eac9affb97e50646344a (patch) | |
tree | f1af7320d7b6be6be059216d0ad08ac7b4f73fd0 /xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx')
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx | 226 |
1 files changed, 48 insertions, 178 deletions
diff --git a/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx b/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx index 50fa285..c789fa6 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx @@ -1,14 +1,10 @@ // file : xsd/cxx/xml/dom/parsing-source.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#if _XERCES_VERSION >= 30000 -# include <xercesc/dom/DOMLSParser.hpp> -# include <xercesc/dom/DOMLSException.hpp> -#else -# include <xercesc/dom/DOMBuilder.hpp> -#endif +#include <xercesc/dom/DOMLSParser.hpp> +#include <xercesc/dom/DOMLSException.hpp> + #include <xercesc/dom/DOMNamedNodeMap.hpp> #include <xercesc/dom/DOMImplementation.hpp> #include <xercesc/dom/DOMImplementationRegistry.hpp> @@ -33,9 +29,9 @@ namespace xsd // template <typename C> parser<C>:: - parser (const xercesc::DOMElement& e, bool ep, bool ap) + parser (const xercesc::DOMElement& e, bool ep, bool tp, bool ap) : element_ (e), - next_element_ (0), + next_content_ (0), a_ (0), ai_ (0) { @@ -43,10 +39,21 @@ namespace xsd if (ep) { - for (next_element_ = e.getFirstChild (); - next_element_ != 0 && - next_element_->getNodeType () != DOMNode::ELEMENT_NODE; - next_element_ = next_element_->getNextSibling ()) /*noop*/; + for (next_content_ = e.getFirstChild ();; + next_content_ = next_content_->getNextSibling ()) + { + if (next_content_ == 0) + break; + + DOMNode::NodeType t (next_content_->getNodeType ()); + + if (t == DOMNode::ELEMENT_NODE) + break; + + if (tp && (t == DOMNode::TEXT_NODE || + t == DOMNode::CDATA_SECTION_NODE)) + break; + } } if (ap) @@ -58,20 +65,31 @@ namespace xsd template <typename C> void parser<C>:: - next_element () + next_content (bool tp) { using xercesc::DOMNode; - for (next_element_ = next_element_->getNextSibling (); - next_element_ != 0 && - next_element_->getNodeType () != DOMNode::ELEMENT_NODE; - next_element_ = next_element_->getNextSibling ())/*noop*/; + for (next_content_ = next_content_->getNextSibling ();; + next_content_ = next_content_->getNextSibling ()) + { + if (next_content_ == 0) + break; + + DOMNode::NodeType t (next_content_->getNodeType ()); + + if (t == DOMNode::ELEMENT_NODE) + break; + + if (tp && (t == DOMNode::TEXT_NODE || + t == DOMNode::CDATA_SECTION_NODE)) + break; + } } // parse() // template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (xercesc::InputSource& is, error_handler<C>& eh, const properties<C>& prop, @@ -82,28 +100,13 @@ namespace xsd } template <typename C> - auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (xercesc::InputSource& is, xercesc::DOMErrorHandler& eh, const properties<C>& prop, unsigned long flags) { - // HP aCC cannot handle using namespace xercesc; - // - using xercesc::DOMImplementationRegistry; - using xercesc::DOMImplementationLS; - using xercesc::DOMImplementation; - using xercesc::DOMDocument; -#if _XERCES_VERSION >= 30000 - using xercesc::DOMLSParser; - using xercesc::DOMConfiguration; -#else - using xercesc::DOMBuilder; -#endif - - using xercesc::Wrapper4InputSource; - using xercesc::XMLUni; - + using namespace xercesc; // Instantiate the DOM parser. // @@ -116,8 +119,7 @@ namespace xsd DOMImplementation* impl ( DOMImplementationRegistry::getDOMImplementation (ls_id)); -#if _XERCES_VERSION >= 30000 - auto_ptr<DOMLSParser> parser ( + XSD_DOM_AUTO_PTR<DOMLSParser> parser ( impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); DOMConfiguration* conf (parser->getDomConfig ()); @@ -163,7 +165,6 @@ namespace xsd if (!(flags & no_muliple_imports)) conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true); #endif - // This feature checks the schema grammar for additional // errors. We most likely do not need it when validating // instances (assuming the schema is valid). @@ -214,64 +215,9 @@ namespace xsd bits::error_handler_proxy<C> ehp (eh); conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); -#else // _XERCES_VERSION >= 30000 - - // Same as above but for Xerces-C++ 2 series. - // - auto_ptr<DOMBuilder> parser ( - impl->createDOMBuilder (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); - - parser->setFeature (XMLUni::fgDOMComments, false); - parser->setFeature (XMLUni::fgDOMDatatypeNormalization, true); - parser->setFeature (XMLUni::fgDOMEntities, false); - parser->setFeature (XMLUni::fgDOMNamespaces, true); - parser->setFeature (XMLUni::fgDOMWhitespaceInElementContent, false); - - if (flags & dont_validate) - { - parser->setFeature (XMLUni::fgDOMValidation, false); - parser->setFeature (XMLUni::fgXercesSchema, false); - parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); - } - else - { - parser->setFeature (XMLUni::fgDOMValidation, true); - parser->setFeature (XMLUni::fgXercesSchema, true); - parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); - } - - parser->setFeature (XMLUni::fgXercesUserAdoptsDOMDocument, true); - - if (!prop.schema_location ().empty ()) - { - xml::string sl (prop.schema_location ()); - const void* v (sl.c_str ()); - - parser->setProperty ( - XMLUni::fgXercesSchemaExternalSchemaLocation, - const_cast<void*> (v)); - } - - if (!prop.no_namespace_schema_location ().empty ()) - { - xml::string sl (prop.no_namespace_schema_location ()); - const void* v (sl.c_str ()); - - parser->setProperty ( - XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, - const_cast<void*> (v)); - } - - bits::error_handler_proxy<C> ehp (eh); - parser->setErrorHandler (&ehp); - -#endif // _XERCES_VERSION >= 30000 - xercesc::Wrapper4InputSource wrap (&is, false); -#if _XERCES_VERSION >= 30000 - auto_ptr<DOMDocument> doc; - + XSD_DOM_AUTO_PTR<DOMDocument> doc; try { doc.reset (parser->parse (&wrap)); @@ -279,9 +225,7 @@ namespace xsd catch (const xercesc::DOMLSException&) { } -#else - auto_ptr<DOMDocument> doc (parser->parse (wrap)); -#endif + if (ehp.failed ()) doc.reset (); @@ -289,7 +233,7 @@ namespace xsd } template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (const std::basic_string<C>& uri, error_handler<C>& eh, const properties<C>& prop, @@ -300,26 +244,13 @@ namespace xsd } template <typename C> - auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (const std::basic_string<C>& uri, xercesc::DOMErrorHandler& eh, const properties<C>& prop, unsigned long flags) { - // HP aCC cannot handle using namespace xercesc; - // - using xercesc::DOMImplementationRegistry; - using xercesc::DOMImplementationLS; - using xercesc::DOMImplementation; - using xercesc::DOMDocument; -#if _XERCES_VERSION >= 30000 - using xercesc::DOMLSParser; - using xercesc::DOMConfiguration; -#else - using xercesc::DOMBuilder; -#endif - using xercesc::XMLUni; - + using namespace xercesc; // Instantiate the DOM parser. // @@ -332,8 +263,7 @@ namespace xsd DOMImplementation* impl ( DOMImplementationRegistry::getDOMImplementation (ls_id)); -#if _XERCES_VERSION >= 30000 - auto_ptr<DOMLSParser> parser ( + XSD_DOM_AUTO_PTR<DOMLSParser> parser ( impl->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0)); DOMConfiguration* conf (parser->getDomConfig ()); @@ -430,63 +360,7 @@ namespace xsd bits::error_handler_proxy<C> ehp (eh); conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); -#else // _XERCES_VERSION >= 30000 - - // Same as above but for Xerces-C++ 2 series. - // - auto_ptr<DOMBuilder> parser ( - impl->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0)); - - parser->setFeature (XMLUni::fgDOMComments, false); - parser->setFeature (XMLUni::fgDOMDatatypeNormalization, true); - parser->setFeature (XMLUni::fgDOMEntities, false); - parser->setFeature (XMLUni::fgDOMNamespaces, true); - parser->setFeature (XMLUni::fgDOMWhitespaceInElementContent, false); - - if (flags & dont_validate) - { - parser->setFeature (XMLUni::fgDOMValidation, false); - parser->setFeature (XMLUni::fgXercesSchema, false); - parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); - } - else - { - parser->setFeature (XMLUni::fgDOMValidation, true); - parser->setFeature (XMLUni::fgXercesSchema, true); - parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); - } - - parser->setFeature (XMLUni::fgXercesUserAdoptsDOMDocument, true); - - if (!prop.schema_location ().empty ()) - { - xml::string sl (prop.schema_location ()); - const void* v (sl.c_str ()); - - parser->setProperty ( - XMLUni::fgXercesSchemaExternalSchemaLocation, - const_cast<void*> (v)); - } - - if (!prop.no_namespace_schema_location ().empty ()) - { - xml::string sl (prop.no_namespace_schema_location ()); - const void* v (sl.c_str ()); - - parser->setProperty ( - XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, - const_cast<void*> (v)); - } - - bits::error_handler_proxy<C> ehp (eh); - parser->setErrorHandler (&ehp); - -#endif // _XERCES_VERSION >= 30000 - - -#if _XERCES_VERSION >= 30000 - auto_ptr<DOMDocument> doc; - + XSD_DOM_AUTO_PTR<DOMDocument> doc; try { doc.reset (parser->parseURI (string (uri).c_str ())); @@ -494,10 +368,6 @@ namespace xsd catch (const xercesc::DOMLSException&) { } -#else - auto_ptr<DOMDocument> doc ( - parser->parseURI (string (uri).c_str ())); -#endif if (ehp.failed ()) doc.reset (); |