From 5006cc37b0b0de8e4c0527e73e11ca71653602fb Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Tue, 20 Jan 2026 13:12:20 +0200 Subject: [PATCH] When namespace count reaches 0 it will not be erased and never again inserted Signed-off-by: Raul Metsma --- cdoc/XmlWriter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cdoc/XmlWriter.cpp b/cdoc/XmlWriter.cpp index 24715b10..0ef87193 100644 --- a/cdoc/XmlWriter.cpp +++ b/cdoc/XmlWriter.cpp @@ -49,9 +49,9 @@ int64_t XMLWriter::writeStartElement(NS ns, const std::string &name, const std:: { if(!w) return WRONG_ARGUMENTS; - auto [pos, inserted] = nsmap.emplace(ns.prefix ? ns.prefix : "", 0); - pos->second++; - if(xmlTextWriterStartElementNS(w.get(), pcxmlChar(ns.prefix), pcxmlChar(name.c_str()), inserted ? pcxmlChar(ns.ns) : nullptr) == -1) + auto &count = nsmap[ns.prefix ? ns.prefix : std::string_view{}]; + count++; + if(xmlTextWriterStartElementNS(w.get(), pcxmlChar(ns.prefix), pcxmlChar(name.c_str()), count > 1 ? nullptr : pcxmlChar(ns.ns)) == -1) return IO_ERROR; for(const auto &[name, content]: attr) {