[gxml] * when you append a child from one document to another, where the nodes are backed by libxml2, use x



commit 0c749455c494f6f35653d82c173c2084fc72b946
Author: Richard Schwarting <aquarichy gmail com>
Date:   Fri Jul 6 02:34:52 2012 -0400

    * when you append a child from one document to another, where the nodes are backed by libxml2, use xmlNodeDocCopy to ensure independence between the copy and the original.  Similar changes may need to be made elsewhere, or at least have owner_document change

 gxml/BackedNode.vala |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/gxml/BackedNode.vala b/gxml/BackedNode.vala
index 11fd7f6..2fc0c0c 100644
--- a/gxml/BackedNode.vala
+++ b/gxml/BackedNode.vala
@@ -244,7 +244,18 @@ namespace GXmlDom {
 		 * { inheritDoc}
 		 */
 		public override XNode? append_child (XNode new_child) /*throws DomError*/ {
-			return this.child_nodes.append_child (new_child);
+			if (new_child.owner_document != this.owner_document && new_child.get_type ().is_a (typeof (GXmlDom.BackedNode))) {
+				/* The point here is that a node from another document should
+				   have a copy made to be integrated into this one, so we don't
+				   mess up the other document.  (TODO: consider removing it from
+				   the originating document.)  The node's references should be
+				   updated to this one. */
+				new_child.owner_document.sync_dirty_elements ();
+				Xml.Node *node_copy = ((BackedNode)new_child).node->doc_copy (this.owner_document.xmldoc, 1);
+				return this.child_nodes.append_child (this.owner_document.lookup_node (node_copy));
+			} else {
+				return this.child_nodes.append_child (new_child);
+			}
 		}
 		/**
 		 * { inheritDoc}



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