2002-04-12 Duncan Mak <duncan@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlNamedNodeMap.cs
index 1a4b297f0d8a99192b423ab6d3364a456a4f8caf..d9cd04a6426c9658dc60d4d809d820b51e643e27 100644 (file)
@@ -15,8 +15,9 @@ namespace System.Xml
 {
        public class XmlNamedNodeMap : IEnumerable
        {
-               private XmlNode parent;
-               private ArrayList nodeList;
+               XmlNode parent;
+               ArrayList nodeList;
+               bool readOnly = false;
 
                internal XmlNamedNodeMap (XmlNode parent)
                {
@@ -28,10 +29,9 @@ namespace System.Xml
                        get { return nodeList.Count; }
                }
 
-               [MonoTODO]
                public virtual IEnumerator GetEnumerator () 
                {
-                       throw new NotImplementedException ();
+                       return nodeList.GetEnumerator ();
                }
 
                public virtual XmlNode GetNamedItem (string name)
@@ -43,10 +43,15 @@ namespace System.Xml
                        return null;
                }
 
-               [MonoTODO]
                public virtual XmlNode GetNamedItem (string localName, string namespaceURI)
                {
-                       throw new NotImplementedException ();
+                       foreach (XmlNode node in nodeList) {
+                               if ((node.Name == localName)
+                                   && (parent.NamespaceURI == namespaceURI))
+                                       return node;
+                       }
+
+                       return null;
                }
                
                public virtual XmlNode Item (int index)
@@ -57,23 +62,43 @@ namespace System.Xml
                                return (XmlNode) nodeList [index];
                }
 
-               [MonoTODO]
                public virtual XmlNode RemoveNamedItem (string name)
-               {
-                       throw new NotImplementedException ();
+               {                       
+                       foreach (XmlNode node in nodeList)
+                               if (node.Name == name) {
+                                       nodeList.Remove (node);
+                                       return node;
+                               }
+                       
+                       return null;
                }
 
-               [MonoTODO]
                public virtual XmlNode RemoveNamedItem (string localName, string namespaceURI)
                {
-                       throw new NotImplementedException ();
+                       foreach (XmlNode node in nodeList)
+                               if ((node.Name == localName)
+                                   && (parent.NamespaceURI == namespaceURI)) {
+                                       nodeList.Remove (node);
+                                       return node;
+                               }
+
+                       return null;
                }
 
-               [MonoTODO]
                public virtual XmlNode SetNamedItem (XmlNode node)
                {
+                       if (readOnly || (node.OwnerDocument != parent.OwnerDocument))
+                               throw new ArgumentException ("Cannot add to NodeMap.");
+                                               
+                       foreach (XmlNode x in nodeList)
+                               if (x.Name == node.Name) {
+                                       nodeList.Remove (x);
+                                       nodeList.Add (x);
+                                       return x;
+                               }
+                       
                        nodeList.Add (node);
-                       return node;
+                       return null;
                }
        }
 }