implementing XmlElement.SetAttributeNode(localName, namespaceURI) and
[mono.git] / mcs / class / System.XML / System.Xml / XmlNode.cs
index 48744fad3c81f8879d3ce3ea7ca3f45c16044a81..d4d39a77aef518963f4a3e34284010eeb8e3f7b9 100644 (file)
@@ -40,10 +40,9 @@ namespace System.Xml
                        get { return null; }
                }
 
-               [MonoTODO]
                public virtual string BaseURI
                {
-                       get { throw new NotImplementedException (); }
+                       get { return ParentNode.BaseURI; }
                }
 
                public virtual XmlNodeList ChildNodes {
@@ -78,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;
                        }
@@ -198,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;
 
@@ -214,6 +220,8 @@ namespace System.Xml
                                
                                LastLinkedChild = newLinkedChild;
 
+                               ownerDoc.onNodeInserted (newChild, newChild.ParentNode);
+
                                return newChild;
                        } else
                                throw new InvalidOperationException();
@@ -228,7 +236,7 @@ namespace System.Xml
                public abstract XmlNode CloneNode (bool deep);
 
                [MonoTODO]
-               public virtual XPathNavigator CreateNavigator ()
+               public XPathNavigator CreateNavigator ()
                {
                        return new XmlDocumentNavigator(this);
                }
@@ -286,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)
@@ -312,6 +326,8 @@ namespace System.Xml
                                        oldLinkedChild.NextLinkedSibling = null;
                                 }
 
+                               OwnerDocument.onNodeRemoved (oldChild, oldChild.ParentNode);
+
                                return oldChild;
                        } 
                        else
@@ -324,28 +340,43 @@ namespace System.Xml
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public XmlNodeList SelectNodes (string xpath)
                {
-                       throw new NotImplementedException ();
+                       return SelectNodes (xpath, null);
                }
 
                [MonoTODO]
                public XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
                {
-                       throw new NotImplementedException ();
+                       XPathNavigator nav = CreateNavigator ();
+                       XPathExpression expr = nav.Compile (xpath);
+                       if (nsmgr != null)
+                               expr.SetContext (nsmgr);
+                       XPathNodeIterator iter = nav.Select (expr);
+                       ArrayList rgNodes = new ArrayList ();
+                       while (iter.MoveNext ())
+                       {
+                               rgNodes.Add (((XmlDocumentNavigator) iter.Current).Node);
+                       }
+                       return new XmlNodeArrayList (rgNodes);
                }
 
-               [MonoTODO]
                public XmlNode SelectSingleNode (string xpath)
                {
-                       throw new NotImplementedException ();
+                       return SelectSingleNode (xpath, null);
                }
 
                [MonoTODO]
                public XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
                {
-                       throw new NotImplementedException ();
+                       XPathNavigator nav = CreateNavigator ();
+                       XPathExpression expr = nav.Compile (xpath);
+                       if (nsmgr != null)
+                               expr.SetContext (nsmgr);
+                       XPathNodeIterator iter = nav.Select (expr);
+                       if (!iter.MoveNext ())
+                               return null;
+                       return ((XmlDocumentNavigator) iter.Current).Node;
                }
 
                internal void SetParentNode (XmlNode parent)