diff options
Diffstat (limited to 'xsd/libxsd/xsd/cxx/xml/dom')
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx | 83 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx | 3 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx | 15 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/elements.hxx | 3 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/elements.txx | 3 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/parsing-header.hxx | 3 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/parsing-source.hxx | 45 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/parsing-source.txx | 226 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/serialization-header.hxx | 3 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/serialization-header.txx | 17 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/serialization-source.hxx | 21 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/serialization-source.txx | 189 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx | 5 | ||||
-rw-r--r-- | xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.txx | 7 |
14 files changed, 261 insertions, 362 deletions
diff --git a/xsd/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx b/xsd/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx index f22e652..fc8f194 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/auto-ptr.hxx @@ -1,11 +1,18 @@ // file : xsd/cxx/xml/dom/auto-ptr.hxx -// 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 #ifndef XSD_CXX_XML_DOM_AUTO_PTR_HXX #define XSD_CXX_XML_DOM_AUTO_PTR_HXX +#include <xsd/cxx/config.hxx> // XSD_CXX11_* + +#ifdef XSD_CXX11 +# include <memory> // std::unique_ptr +# include <utility> // std::move +# include <type_traits> // std::remove_const +#endif + namespace xsd { namespace cxx @@ -14,9 +21,73 @@ namespace xsd { namespace dom { - // Simple auto_ptr version that calls release() instead of delete. - // +#ifdef XSD_CXX11 + template <typename T> + struct deleter + { + void + operator() (T* p) const + { + if (p != 0) + const_cast<typename std::remove_const<T>::type*> (p)->release (); + } + }; + +#ifdef XSD_CXX11_TEMPLATE_ALIAS + template <typename T> + using unique_ptr = std::unique_ptr<T, deleter<T>>; +#else + template <typename T> + class unique_ptr: public std::unique_ptr<T, deleter<T>> + { + public: + typedef std::unique_ptr<T, deleter<T>> base; + + typedef typename base::pointer pointer; + typedef T element_type; + typedef deleter<T> deleter_type; + + unique_ptr (): base () {} + explicit unique_ptr (pointer p): base (p) {} + unique_ptr (pointer p, const deleter_type& d): base (p, d) {} + unique_ptr (pointer p, deleter_type&& d): base (p, std::move (d)) {} + unique_ptr (unique_ptr&& p): base (std::move (p)) {} + template <class T1> + unique_ptr (unique_ptr<T1>&& p): base (std::move (p)) {} + template <class T1> + unique_ptr (std::auto_ptr<T1>&& p): base (std::move (p)) {} + + unique_ptr& operator= (unique_ptr&& p) + { + static_cast<base&> (*this) = std::move (p); + return *this; + } + template <class T1> + unique_ptr& operator= (unique_ptr<T1>&& p) + { + static_cast<base&> (*this) = std::move (p); + return *this; + } + +#ifdef XSD_CXX11_NULLPTR + unique_ptr (std::nullptr_t p): base (p) {} + + unique_ptr& operator= (std::nullptr_t p) + { + static_cast<base&> (*this) = p; + return *this; + } +#endif + }; +#endif // XSD_CXX11_TEMPLATE_ALIAS + +#define XSD_DOM_AUTO_PTR xsd::cxx::xml::dom::unique_ptr + +#else + // Simple auto_ptr version for C++98 that calls release() instead + // of delete. + // template <typename T> struct remove_c { @@ -150,6 +221,10 @@ namespace xsd private: T* x_; }; + +#define XSD_DOM_AUTO_PTR xsd::cxx::xml::dom::auto_ptr + +#endif // XSD_CXX11 } } } diff --git a/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx b/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx index 83e9a7e..01111e1 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/bits/error-handler-proxy.hxx -// 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 #ifndef XSD_CXX_XML_DOM_BITS_ERROR_HANDLER_PROXY_HXX diff --git a/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx b/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx index 23e71cd..7e5579b 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/bits/error-handler-proxy.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/bits/error-handler-proxy.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 #include <xsd/cxx/xml/string.hxx> @@ -53,24 +52,12 @@ namespace xsd xercesc::DOMLocator* loc (e.getLocation ()); -#if _XERCES_VERSION >= 30000 return eh_->handle ( transcode<C> (loc->getURI ()), static_cast<unsigned long> (loc->getLineNumber ()), static_cast<unsigned long> (loc->getColumnNumber ()), s, transcode<C> (e.getMessage ())); -#else - XMLSSize_t l (loc->getLineNumber ()); - XMLSSize_t c (loc->getColumnNumber ()); - - return eh_->handle ( - transcode<C> (loc->getURI ()), - (l == -1 ? 0 : static_cast<unsigned long> (l)), - (c == -1 ? 0 : static_cast<unsigned long> (c)), - s, - transcode<C> (e.getMessage ())); -#endif } } } diff --git a/xsd/libxsd/xsd/cxx/xml/dom/elements.hxx b/xsd/libxsd/xsd/cxx/xml/dom/elements.hxx index e8ce8d2..613b978 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/elements.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/elements.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/elements.hxx -// 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 #ifndef XSD_CXX_XML_DOM_ELEMENTS_HXX diff --git a/xsd/libxsd/xsd/cxx/xml/dom/elements.txx b/xsd/libxsd/xsd/cxx/xml/dom/elements.txx index 540d0fb..c493676 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/elements.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/elements.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/elements.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 #include <xsd/cxx/xml/string.hxx> diff --git a/xsd/libxsd/xsd/cxx/xml/dom/parsing-header.hxx b/xsd/libxsd/xsd/cxx/xml/dom/parsing-header.hxx index d9a3695..f9ec033 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/parsing-header.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/parsing-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/parsing-header.hxx -// 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 #ifndef XSD_CXX_XML_DOM_PARSING_HEADER_HXX diff --git a/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.hxx b/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.hxx index 2c90cf3..fac1006 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/parsing-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/parsing-source.hxx -// 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 #ifndef XSD_CXX_XML_DOM_PARSING_SOURCE_HXX @@ -19,7 +18,6 @@ #include <xsd/cxx/xml/elements.hxx> // properies #include <xsd/cxx/xml/error-handler.hxx> - #include <xsd/cxx/xml/dom/auto-ptr.hxx> #include <xsd/cxx/xml/dom/elements.hxx> // name #include <xsd/cxx/xml/dom/parsing-header.hxx> @@ -32,30 +30,47 @@ namespace xsd { namespace dom { - // Parser state object. Can be used for parsing element, attributes, - // or both. + // Parser state object. Can be used for parsing elements (and + // optionally text), attributes, or both. // template <typename C> class parser { public: - parser (const xercesc::DOMElement& e, bool ep, bool ap); + parser (const xercesc::DOMElement& e, bool ep, bool tp, bool ap); + // Content parsing. + // bool - more_elements () + more_content () { - return next_element_ != 0; + return next_content_ != 0; } const xercesc::DOMElement& cur_element () { - return *static_cast<const xercesc::DOMElement*> (next_element_); + return *static_cast<const xercesc::DOMElement*> (next_content_); + } + + const xercesc::DOMText& + cur_text () + { + return *static_cast<const xercesc::DOMText*> (next_content_); + } + + bool + cur_is_text () + { + return next_content_->getNodeType () != + xercesc::DOMNode::ELEMENT_NODE; } void - next_element (); + next_content (bool text); + // Attribute parsing. + // bool more_attributes () { @@ -88,7 +103,7 @@ namespace xsd private: const xercesc::DOMElement& element_; - const xercesc::DOMNode* next_element_; + const xercesc::DOMNode* next_content_; const xercesc::DOMNamedNodeMap* a_; XMLSize_t ai_; // Index of the next DOMAttr. @@ -102,28 +117,28 @@ namespace xsd const unsigned long no_muliple_imports = 0x00000800UL; template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (xercesc::InputSource&, error_handler<C>&, const properties<C>&, unsigned long flags); template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (xercesc::InputSource&, xercesc::DOMErrorHandler&, const properties<C>&, unsigned long flags); 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>&, const properties<C>&, unsigned long flags); template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> parse (const std::basic_string<C>& uri, xercesc::DOMErrorHandler&, const properties<C>&, 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 (); diff --git a/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.hxx b/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.hxx index 3b879b1..a3cbff4 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/serialization-header.hxx -// 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 #ifndef XSD_CXX_XML_DOM_SERIALIZATION_HEADER_HXX diff --git a/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.txx b/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.txx index 3052b7e..6e58cfd 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/serialization-header.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/serialization-header.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 #include <vector> @@ -33,12 +32,8 @@ namespace xsd prefix (const C* ns, xercesc::DOMElement& e, const C* hint) { string xns (ns); - -#if _XERCES_VERSION >= 30000 const XMLCh* p (e.lookupPrefix (xns.c_str ())); -#else - const XMLCh* p (e.lookupNamespacePrefix (xns.c_str (), false)); -#endif + if (p != 0) return transcode<C> (p); @@ -125,13 +120,7 @@ namespace xsd void clear (xercesc::DOMElement& e) { - // HP aCC cannot handle using namespace xercesc; - // - using xercesc::DOMNode; - using xercesc::DOMAttr; - using xercesc::DOMNamedNodeMap; - using xercesc::XMLString; - using xercesc::SchemaSymbols; + using namespace xercesc; // Remove child nodes. // diff --git a/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.hxx b/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.hxx index 325c1ec..9056917 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/serialization-source.hxx -// 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 #ifndef XSD_CXX_XML_DOM_SERIALIZATION_SOURCE_HXX @@ -47,13 +46,19 @@ namespace xsd xercesc::DOMElement& create_element (const C* name, const C* ns, xercesc::DOMElement&); + // Add namespace declarations and schema locations. + // + template <typename C> + void + add_namespaces (xercesc::DOMElement&, const namespace_infomap<C>&); + // Serialization flags. // const unsigned long no_xml_declaration = 0x00010000UL; const unsigned long dont_pretty_print = 0x00020000UL; template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> serialize (const std::basic_string<C>& root_element, const std::basic_string<C>& root_element_namespace, const namespace_infomap<C>& map, @@ -62,7 +67,7 @@ namespace xsd // This one helps Sun C++ to overcome its fears. // template <typename C> - inline xml::dom::auto_ptr<xercesc::DOMDocument> + inline XSD_DOM_AUTO_PTR<xercesc::DOMDocument> serialize (const C* root_element, const C* root_element_namespace, const namespace_infomap<C>& map, @@ -103,16 +108,12 @@ namespace xsd public: // I know, some of those consts are stupid. But that's what - // Xerces folks put into their interfaces and VC-7.1 thinks - // there are different signatures if one strips this fluff off. + // Xerces folks put into their interfaces and VC thinks there + // are different signatures if one strips this fluff off. // virtual void writeChars (const XMLByte* const buf, -#if _XERCES_VERSION >= 30000 const XMLSize_t size, -#else - const unsigned int size, -#endif xercesc::XMLFormatter* const) { // Ignore the write request if there was a stream failure and the diff --git a/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.txx b/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.txx index 2b27dd5..eed1196 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/serialization-source.txx @@ -1,18 +1,14 @@ // file : xsd/cxx/xml/dom/serialization-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 #include <xercesc/util/XMLUni.hpp> // xercesc::fg* #include <xercesc/util/XMLUniDefs.hpp> // chLatin_L, etc #include <xercesc/validators/schema/SchemaSymbols.hpp> -#if _XERCES_VERSION >= 30000 -# include <xercesc/dom/DOMLSOutput.hpp> -# include <xercesc/dom/DOMLSSerializer.hpp> -#else -# include <xercesc/dom/DOMWriter.hpp> -#endif +#include <xercesc/dom/DOMLSOutput.hpp> +#include <xercesc/dom/DOMLSSerializer.hpp> + #include <xercesc/dom/DOMElement.hpp> #include <xercesc/dom/DOMImplementation.hpp> #include <xercesc/dom/DOMImplementationRegistry.hpp> @@ -109,70 +105,19 @@ namespace xsd return *e; } - - // - // template <typename C> - auto_ptr<xercesc::DOMDocument> - serialize (const std::basic_string<C>& el, - const std::basic_string<C>& ns, - const namespace_infomap<C>& map, - unsigned long) + void + add_namespaces (xercesc::DOMElement& el, + const namespace_infomap<C>& map) { - // HP aCC cannot handle using namespace xercesc; - // - using xercesc::DOMImplementationRegistry; - using xercesc::DOMImplementation; - using xercesc::DOMDocument; - using xercesc::DOMElement; + using namespace xercesc; - // - // typedef std::basic_string<C> string; typedef namespace_infomap<C> infomap; typedef typename infomap::const_iterator infomap_iterator; C colon (':'), space (' '); - string prefix; - - if (!ns.empty ()) - { - infomap_iterator i (map.begin ()), e (map.end ()); - - for ( ;i != e; ++i) - { - if (i->second.name == ns) - { - prefix = i->first; - break; - } - } - - // Since this is the first namespace in document we don't - // need to worry about conflicts. - // - if (i == e) - prefix = xml::bits::first_prefix<C> (); - } - - const XMLCh ls[] = {xercesc::chLatin_L, - xercesc::chLatin_S, - xercesc::chNull}; - - DOMImplementation* impl ( - DOMImplementationRegistry::getDOMImplementation (ls)); - - auto_ptr<DOMDocument> doc ( - impl->createDocument ( - (ns.empty () ? 0 : xml::string (ns).c_str ()), - xml::string ((prefix.empty () - ? el - : prefix + colon + el)).c_str (), - 0)); - - DOMElement* root (doc->getDocumentElement ()); - // Check if we need to provide xsi mapping. // bool xsi (false); @@ -214,14 +159,14 @@ namespace xsd // Empty prefix. // if (!i->second.name.empty ()) - root->setAttributeNS ( + el.setAttributeNS ( xercesc::XMLUni::fgXMLNSURIName, xml::string (xmlns_prefix).c_str (), xml::string (i->second.name).c_str ()); } else { - root->setAttributeNS ( + el.setAttributeNS ( xercesc::XMLUni::fgXMLNSURIName, xml::string (xmlns_prefix + colon + i->first).c_str (), xml::string (i->second.name).c_str ()); @@ -233,7 +178,7 @@ namespace xsd // if (xsi) xsi_prefix = dom::prefix (xml::bits::xsi_namespace<C> (), - *root, + el, xml::bits::xsi_prefix<C> ()); // Create xsi:schemaLocation and xsi:noNamespaceSchemaLocation @@ -265,7 +210,7 @@ namespace xsd if (!schema_location.empty ()) { - root->setAttributeNS ( + el.setAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xml::string (xsi_prefix + colon + xml::bits::schema_location<C> ()).c_str (), @@ -274,13 +219,68 @@ namespace xsd if (!no_namespace_schema_location.empty ()) { - root->setAttributeNS ( + el.setAttributeNS ( xercesc::SchemaSymbols::fgURI_XSI, xml::string ( xsi_prefix + colon + xml::bits::no_namespace_schema_location<C> ()).c_str (), xml::string (no_namespace_schema_location).c_str ()); } + } + + // + // + template <typename C> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> + serialize (const std::basic_string<C>& el, + const std::basic_string<C>& ns, + const namespace_infomap<C>& map, + unsigned long) + { + using namespace xercesc; + + typedef std::basic_string<C> string; + typedef namespace_infomap<C> infomap; + typedef typename infomap::const_iterator infomap_iterator; + + string prefix; + + if (!ns.empty ()) + { + infomap_iterator i (map.begin ()), e (map.end ()); + + for ( ;i != e; ++i) + { + if (i->second.name == ns) + { + prefix = i->first; + break; + } + } + + // Since this is the first namespace in document we don't + // need to worry about conflicts. + // + if (i == e) + prefix = xml::bits::first_prefix<C> (); + } + + const XMLCh ls[] = {xercesc::chLatin_L, + xercesc::chLatin_S, + xercesc::chNull}; + + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls)); + + XSD_DOM_AUTO_PTR<DOMDocument> doc ( + impl->createDocument ( + (ns.empty () ? 0 : xml::string (ns).c_str ()), + xml::string ((prefix.empty () + ? el + : prefix + C (':') + el)).c_str (), + 0)); + + add_namespaces (*doc->getDocumentElement (), map); return doc; } @@ -294,18 +294,7 @@ namespace xsd xercesc::DOMErrorHandler& eh, unsigned long flags) { - // HP aCC cannot handle using namespace xercesc; - // - using xercesc::DOMImplementationRegistry; - using xercesc::DOMImplementation; -#if _XERCES_VERSION >= 30000 - using xercesc::DOMLSSerializer; - using xercesc::DOMConfiguration; - using xercesc::DOMLSOutput; -#else - using xercesc::DOMWriter; -#endif - using xercesc::XMLUni; + using namespace xercesc; const XMLCh ls[] = {xercesc::chLatin_L, xercesc::chLatin_S, @@ -316,8 +305,7 @@ namespace xsd bits::error_handler_proxy<C> ehp (eh); -#if _XERCES_VERSION >= 30000 - xml::dom::auto_ptr<DOMLSSerializer> writer ( + XSD_DOM_AUTO_PTR<DOMLSSerializer> writer ( impl->createLSSerializer ()); DOMConfiguration* conf (writer->getDomConfig ()); @@ -332,46 +320,27 @@ namespace xsd if (!(flags & dont_pretty_print) && conf->canSetParameter (XMLUni::fgDOMWRTFormatPrettyPrint, true)) + { conf->setParameter (XMLUni::fgDOMWRTFormatPrettyPrint, true); + // Don't add extra new lines between first-level elements. + // + if (conf->canSetParameter (XMLUni::fgDOMWRTXercesPrettyPrint, true)) + conf->setParameter (XMLUni::fgDOMWRTXercesPrettyPrint, false); + } + // See if we need to write XML declaration. // if ((flags & no_xml_declaration) && conf->canSetParameter (XMLUni::fgDOMXMLDeclaration, false)) conf->setParameter (XMLUni::fgDOMXMLDeclaration, false); - xml::dom::auto_ptr<DOMLSOutput> out (impl->createLSOutput ()); + XSD_DOM_AUTO_PTR<DOMLSOutput> out (impl->createLSOutput ()); out->setEncoding (xml::string (encoding).c_str ()); out->setByteStream (&target); - bool r (writer->write (&doc, out.get ())); -#else - xml::dom::auto_ptr<DOMWriter> writer (impl->createDOMWriter ()); - - writer->setErrorHandler (&ehp); - writer->setEncoding (xml::string (encoding).c_str ()); - - // Set some nice features if the serializer supports them. - // - if (writer->canSetFeature ( - XMLUni::fgDOMWRTDiscardDefaultContent, true)) - writer->setFeature (XMLUni::fgDOMWRTDiscardDefaultContent, true); - - if (!(flags & dont_pretty_print) && - writer->canSetFeature (XMLUni::fgDOMWRTFormatPrettyPrint, true)) - writer->setFeature (XMLUni::fgDOMWRTFormatPrettyPrint, true); - - // See if we need to write XML declaration. - // - if ((flags & no_xml_declaration) && - writer->canSetFeature (XMLUni::fgDOMXMLDeclaration, false)) - writer->setFeature (XMLUni::fgDOMXMLDeclaration, false); - - bool r (writer->writeNode (&target, doc)); -#endif - - if (!r || ehp.failed ()) + if (!writer->write (&doc, out.get ()) || ehp.failed ()) return false; return true; diff --git a/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx b/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx index 11d7114..95de764 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx +++ b/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/wildcard-source.hxx -// 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 #ifndef XSD_CXX_XML_DOM_WILDCARD_SOURCE_HXX @@ -19,7 +18,7 @@ namespace xsd namespace dom { template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> create_document (); } } diff --git a/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.txx b/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.txx index 32043c0..cce6922 100644 --- a/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.txx +++ b/xsd/libxsd/xsd/cxx/xml/dom/wildcard-source.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/xml/dom/wildcard-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 #include <xercesc/util/XMLUniDefs.hpp> // chLatin_L, etc @@ -17,7 +16,7 @@ namespace xsd namespace dom { template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> create_document () { const XMLCh ls[] = {xercesc::chLatin_L, @@ -29,7 +28,7 @@ namespace xsd xercesc::DOMImplementation* impl ( xercesc::DOMImplementationRegistry::getDOMImplementation (ls)); - return xml::dom::auto_ptr<xercesc::DOMDocument> ( + return XSD_DOM_AUTO_PTR<xercesc::DOMDocument> ( impl->createDocument ()); } } |