* The Depth property was not implemented correctly and the Read method did not
[mono.git] / mcs / class / System.XML / System.Xml / XmlNode.cs
index 59a5c752aa4603cd041fbcf18c3f72828668a836..d4d39a77aef518963f4a3e34284010eeb8e3f7b9 100644 (file)
@@ -77,12 +77,13 @@ namespace System.Xml
                        set { throw new NotImplementedException (); }
                }
 
-               private void AppendChildValues(XmlNode parent, StringBuilder builder)
+               private void AppendChildValues (XmlNode parent, StringBuilder builder)
                {
                        XmlNode node = parent.FirstChild;
 
                        while (node != null) {
-                               builder.Append (node.Value);
+                               if (node.NodeType == XmlNodeType.Text)
+                                       builder.Append (node.Value);
                                AppendChildValues (node, builder);
                                node = node.NextSibling;
                        }
@@ -197,9 +198,15 @@ namespace System.Xml
 
                public virtual XmlNode AppendChild (XmlNode newChild)
                {
-                       if (NodeType == XmlNodeType.Document
-                           || NodeType == XmlNodeType.Element
-                           || NodeType == XmlNodeType.Attribute) {
+                       XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
+
+                       ownerDoc.onNodeInserting (newChild, this);
+
+                       if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) {
+                               
+                               if (newChild.OwnerDocument != ownerDoc)
+                                       throw new ArgumentException ("Can't append a node created by another document.");
+
                                XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild;
                                XmlLinkedNode lastLinkedChild = LastLinkedChild;
 
@@ -213,6 +220,8 @@ namespace System.Xml
                                
                                LastLinkedChild = newLinkedChild;
 
+                               ownerDoc.onNodeInserted (newChild, newChild.ParentNode);
+
                                return newChild;
                        } else
                                throw new InvalidOperationException();
@@ -227,7 +236,7 @@ namespace System.Xml
                public abstract XmlNode CloneNode (bool deep);
 
                [MonoTODO]
-               public virtual XPathNavigator CreateNavigator ()
+               public XPathNavigator CreateNavigator ()
                {
                        return new XmlDocumentNavigator(this);
                }
@@ -285,11 +294,17 @@ namespace System.Xml
 
                public virtual void RemoveAll ()
                {
+                       XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
+
+                       ownerDoc.onNodeRemoving (this, this.ParentNode);
                        LastLinkedChild = null;
+                       ownerDoc.onNodeRemoved (this, this.ParentNode);
                }
 
                public virtual XmlNode RemoveChild (XmlNode oldChild)
                {
+                       OwnerDocument.onNodeRemoving (oldChild, oldChild.ParentNode);
+
                        if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) 
                        {
                                if (IsReadOnly)
@@ -311,6 +326,8 @@ namespace System.Xml
                                        oldLinkedChild.NextLinkedSibling = null;
                                 }
 
+                               OwnerDocument.onNodeRemoved (oldChild, oldChild.ParentNode);
+
                                return oldChild;
                        } 
                        else