From fac1bf0b0db4aa90472a2dd06c646af145e059a5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 15 Oct 2010 11:34:06 +0200 Subject: Add current element to the parser context --- libxsde/xsde/cxx/parser/context.hxx | 29 +++++++++++++++++++++- libxsde/xsde/cxx/parser/context.ixx | 39 ++++++++++++++++++++++++++++-- libxsde/xsde/cxx/parser/expat/document.cxx | 27 ++++++++++++--------- 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/libxsde/xsde/cxx/parser/context.hxx b/libxsde/xsde/cxx/parser/context.hxx index 9654e57..6019f34 100644 --- a/libxsde/xsde/cxx/parser/context.hxx +++ b/libxsde/xsde/cxx/parser/context.hxx @@ -12,6 +12,8 @@ #include +#include + #ifndef XSDE_EXCEPTIONS # include #endif @@ -44,12 +46,24 @@ namespace xsde class context { public: - context (XML_Parser xml_parser); + context (); + + private: + context (const context&); + context& operator= (const context&); public: XML_Parser xml_parser (); + // Return namespace and name of the current element being parsed. + // + const ro_string& + element_namespace () const; + + const ro_string& + element_name () const; + // Error handling via codes. // public: @@ -125,10 +139,23 @@ namespace xsde #endif // XSDE_PARSER_VALIDATION || !XSDE_EXCEPTIONS public: + void + reset (XML_Parser); + + void + element_namespace (const ro_string&); + + void + element_name (const ro_string&); + + public: parser_state current_; protected: XML_Parser xml_parser_; + + ro_string ns_; + ro_string name_; }; } } diff --git a/libxsde/xsde/cxx/parser/context.ixx b/libxsde/xsde/cxx/parser/context.ixx index 8545389..b3828f5 100644 --- a/libxsde/xsde/cxx/parser/context.ixx +++ b/libxsde/xsde/cxx/parser/context.ixx @@ -20,8 +20,8 @@ namespace xsde // context // inline context:: - context (XML_Parser xml_parser) - : xml_parser_ (xml_parser) + context () + : xml_parser_ (0) { #if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) error_type_ = error_none; @@ -34,6 +34,41 @@ namespace xsde return xml_parser_; } + inline const ro_string& context:: + element_namespace () const + { + return ns_; + } + + inline const ro_string& context:: + element_name () const + { + return name_; + } + + inline void context:: + reset (XML_Parser parser) + { + xml_parser_ = parser; + current_ = parser_state (); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + error_type_ = error_none; +#endif + } + + inline void context:: + element_namespace (const ro_string& ns) + { + ns_.assign (ns); + } + + inline void context:: + element_name (const ro_string& name) + { + name_.assign (name); + } + // // #ifndef XSDE_EXCEPTIONS diff --git a/libxsde/xsde/cxx/parser/expat/document.cxx b/libxsde/xsde/cxx/parser/expat/document.cxx index 84cf7f8..4ce3059 100644 --- a/libxsde/xsde/cxx/parser/expat/document.cxx +++ b/libxsde/xsde/cxx/parser/expat/document.cxx @@ -64,7 +64,7 @@ namespace xsde #else document_pimpl (parser_base& p, const std::string& n) #endif - : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + : first_ (true), xml_parser_ (0), parser_ (&p) { #ifdef XSDE_ENCODING_ISO8859_1 xml_error_ = 0; @@ -86,7 +86,7 @@ namespace xsde const std::string& ns, const std::string& n) #endif - : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + : first_ (true), xml_parser_ (0), parser_ (&p) { #ifdef XSDE_ENCODING_ISO8859_1 xml_error_ = 0; @@ -105,7 +105,7 @@ namespace xsde #else document_pimpl (parser_base& p, const char* n) #endif - : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + : first_ (true), xml_parser_ (0), parser_ (&p) { #ifdef XSDE_ENCODING_ISO8859_1 xml_error_ = 0; @@ -125,7 +125,7 @@ namespace xsde #else document_pimpl (parser_base& p, const char* ns, const char* n) #endif - : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + : first_ (true), xml_parser_ (0), parser_ (&p) { #ifdef XSDE_ENCODING_ISO8859_1 xml_error_ = 0; @@ -138,7 +138,7 @@ namespace xsde document_pimpl:: document_pimpl () - : first_ (true), xml_parser_ (0), context_ (0), parser_ (0) + : first_ (true), xml_parser_ (0), parser_ (0) { #ifdef XSDE_ENCODING_ISO8859_1 xml_error_ = 0; @@ -151,7 +151,7 @@ namespace xsde #ifdef XSDE_POLYMORPHIC document_pimpl:: document_pimpl (const char* n) - : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + : first_ (true), xml_parser_ (0), parser_ (0), polymorphic_ (true) { #ifdef XSDE_ENCODING_ISO8859_1 @@ -162,7 +162,7 @@ namespace xsde document_pimpl:: document_pimpl (const char* ns, const char* n) - : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + : first_ (true), xml_parser_ (0), parser_ (0), polymorphic_ (true) { #ifdef XSDE_ENCODING_ISO8859_1 @@ -174,7 +174,7 @@ namespace xsde #ifdef XSDE_STL document_pimpl:: document_pimpl (const std::string& n) - : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + : first_ (true), xml_parser_ (0), parser_ (0), polymorphic_ (true) { #ifdef XSDE_ENCODING_ISO8859_1 @@ -185,7 +185,7 @@ namespace xsde document_pimpl:: document_pimpl (const std::string& ns, const std::string& n) - : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + : first_ (true), xml_parser_ (0), parser_ (0), polymorphic_ (true) { #ifdef XSDE_ENCODING_ISO8859_1 @@ -416,8 +416,7 @@ namespace xsde void document_pimpl:: parse_begin (XML_Parser parser) { - context_ = context (parser); - + context_.reset (parser); xml_parser_ = parser; set (); } @@ -671,6 +670,9 @@ namespace xsde const ro_string ns (ns_p, ns_s); const ro_string name (name_p, name_s); + context_.element_namespace (ns); + context_.element_name (name); + #ifdef XSDE_POLYMORPHIC const char* type = 0; string type_holder; @@ -1046,6 +1048,9 @@ namespace xsde const ro_string ns (ns_p, ns_s); const ro_string name (name_p, name_s); + context_.element_namespace (ns); + context_.element_name (name); + parser_state& cur = context_.current_; if (cur.depth_ == 0) -- cgit v1.1