[libxml++] Element::set_namespace_declaration(): No error to set the same URI twice.



commit 6dc66f24c260739ae50954efc00f0bd595e30655
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Oct 25 10:41:16 2012 +0200

    Element::set_namespace_declaration(): No error to set the same URI twice.
    
    * libxml++/nodes/element.[h|cc]: Don't throw an exception from
    set_namespace_declaration(), if a namespace prefix is assigned the same URI
    twice. Bug #635846, comment 27.

 ChangeLog                 |    8 ++++++++
 libxml++/nodes/element.cc |   11 +++++++++--
 libxml++/nodes/element.h  |    2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b1988ef..e02cd4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-10-25  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+
+	Element::set_namespace_declaration(): No error to set the same URI twice.
+
+	* libxml++/nodes/element.[h|cc]: Don't throw an exception from
+	set_namespace_declaration(), if a namespace prefix is assigned the same URI
+	twice. Bug #635846, comment 27.
+
 2012-10-10  Kjell Ahlstedt  <kjell ahlstedt bredband net>
 
 	Require libxml-2.0 >= 2.7.3.
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index 73a128a..d45a808 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -227,8 +227,15 @@ void Element::set_namespace_declaration(const Glib::ustring& ns_uri, const Glib:
   xmlNs* ns = xmlNewNs(cobj(), (const xmlChar*)(ns_uri.empty() ? 0 : ns_uri.c_str()),
                        (const xmlChar*)(ns_prefix.empty() ? 0 : ns_prefix.c_str()) );
   if (!ns)
-    throw exception("Could not add namespace declaration with URI=" + ns_uri +
-                    ", prefix=" + ns_prefix);
+  {
+    // Not an error, if we try to assign the same uri to the prefix once again.
+    ns = xmlSearchNs(cobj()->doc, cobj(),
+                     (const xmlChar*)(ns_prefix.empty() ? 0 : ns_prefix.c_str()));
+    const char* const previous_href = (ns && ns->href) ? (const char*)ns->href : "";
+    if (!ns || ns_uri != previous_href)
+      throw exception("Could not add namespace declaration with URI=" + ns_uri +
+                      ", prefix=" + ns_prefix);
+  }
   //We ignore the returned xmlNs*. It's owned by the XML_ELEMENT_NODE.
 }
 
diff --git a/libxml++/nodes/element.h b/libxml++/nodes/element.h
index a727989..65b7f56 100644
--- a/libxml++/nodes/element.h
+++ b/libxml++/nodes/element.h
@@ -34,7 +34,7 @@ public:
    * @param ns_prefix The namespace prefix. If no prefix is specified then the
    *                  namespace URI will be the default namespace.
    * @throws xmlpp::exception If a new namespace node cannot be created,
-   *         e.g. because a namespace with the same prefix already exists.
+   *         e.g. because a namespace with the same prefix but another URI already exists.
    */
   void set_namespace_declaration(const Glib::ustring& ns_uri, const Glib::ustring& ns_prefix = Glib::ustring());
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]