[libxml++] Element::set_namespace_declaration(): Update the node's associated namespace



commit 43c8deddb4fc7e90242d51068856ac9e2e03a896
Author: Mathias Lorente <mathias lorente gadz org>
Date:   Fri Oct 10 16:40:26 2014 +0200

    Element::set_namespace_declaration(): Update the node's associated namespace
    
    * libxml++/nodes/element.cc: Update the node's associated namespace, if the
    added namespace prefix is the same as the node's own namespace prefix.
    * libxml++/nodes/element.h: Mention in the documentation that child nodes
    are not updated. Bug #737682.

 libxml++/nodes/element.cc |    6 ++++++
 libxml++/nodes/element.h  |    9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/libxml++/nodes/element.cc b/libxml++/nodes/element.cc
index d45a808..ceb3cb9 100644
--- a/libxml++/nodes/element.cc
+++ b/libxml++/nodes/element.cc
@@ -236,6 +236,12 @@ void Element::set_namespace_declaration(const Glib::ustring& ns_uri, const Glib:
       throw exception("Could not add namespace declaration with URI=" + ns_uri +
                       ", prefix=" + ns_prefix);
   }
+  if (ns_prefix == get_namespace_prefix())
+  {
+    // Assign namespace directly if the prefix equals the node's own namespace prefix.
+    // This is not done by xmlNewNs(). (See https://bugzilla.gnome.org/show_bug.cgi?id=737682)
+    set_namespace(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 65b7f56..0901868 100644
--- a/libxml++/nodes/element.h
+++ b/libxml++/nodes/element.h
@@ -28,7 +28,14 @@ public:
 
   typedef std::list<Attribute*> AttributeList;
 
-  /** This adds a namespace declaration to this node which will apply to this node and all children.
+  /** Add a namespace declaration to this node which will apply to this node and all children.
+   *
+   * If the added namespace prefix is equal to the prefix associated to the node,
+   * the associated namespace of the node itself is updated, but child nodes are
+   * not updated. If you use this method on a node after children have been added,
+   * it may be necessary to save the XML document and reparse it to get correct
+   * namespaces on all nodes.
+   *
    * @param ns_uri The namespace to associate with the prefix,
    *               or to use as the default namespace if no prefix is specified.
    * @param ns_prefix The namespace prefix. If no prefix is specified then the


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