From 939d5ad2a285a42819a39f7155ed3f672014d4ed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 11 Mar 2015 15:35:11 +0200 Subject: Update namespace stack when resetting document in streaming example --- examples/cxx/tree/streaming/serializer.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/examples/cxx/tree/streaming/serializer.cxx b/examples/cxx/tree/streaming/serializer.cxx index 0ce8156..e6513bc 100644 --- a/examples/cxx/tree/streaming/serializer.cxx +++ b/examples/cxx/tree/streaming/serializer.cxx @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -216,6 +217,7 @@ public: fNamespaceStack->addElement(namespaceMap); } namespaceMap->put((void*)prefix,(XMLCh*)uri); + *fFormatter << XMLFormatter::NoEscapes << chSpace << XMLUni::fgXMLNSString << chColon << prefix << chEqual << chDoubleQuote @@ -327,6 +329,29 @@ public: using DOMLSSerializerImpl::write; // Whole document. +public: + // Update the namespace stack to point to the strings from the + // new document's string pool. + // + void + update_namespace_stack (DOMDocument& d) + { + DOMDocumentImpl& di (dynamic_cast (d)); + + for (XMLSize_t i (0); i != fNamespaceStack->size (); ++i) + { + RefHashTableOf& t (*fNamespaceStack->elementAt (i)); + RefHashTableOfEnumerator e (&t, false, fMemoryManager); + while (e.hasMoreElements ()) + { + XMLCh* k ((XMLCh*) (e.nextElementKey ())); + XMLCh* v (t.get (k)); + t.put ((void*) (di.getPooledString (k)), + (XMLCh*) (di.getPooledString (v))); + } + } + } + private: XMLFormatTarget* target_; std::auto_ptr formatter_; @@ -551,6 +576,10 @@ clear_document () } } + // Update the namespace stack to use the new document. + // + serializer_->update_namespace_stack (*doc); + doc_ = doc; element_count_ = 0; } -- cgit v1.1