2003-10-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlAttributeCollection.cs
index a434ed72536c709b9e5c180a3fac437f25222ce0..0cede171c200061a41bfa4f224c42f10633fde4c 100644 (file)
@@ -29,15 +29,11 @@ namespace System.Xml
                }
 
                bool ICollection.IsSynchronized {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return false; }
                }
 
                bool IsReadOnly {
-                       get {
-                               return ownerElement.IsReadOnly;
-                       }
+                       get { return ownerElement.IsReadOnly; }
                }
 
                [System.Runtime.CompilerServices.IndexerName ("ItemOf")]
@@ -62,9 +58,7 @@ namespace System.Xml
                }
 
                object ICollection.SyncRoot {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return this; }
                }
 
                
@@ -173,13 +167,28 @@ namespace System.Xml
                                RemoveIdenticalAttribute (retAttr);
                                ownerDocument.onNodeRemoved (node, null);
                        }
+                       // If it is default, then directly create new attribute.
+                       if (!retAttr.Specified) {
+                               XmlAttribute attr = ownerDocument.CreateAttribute (retAttr.Prefix,
+                                       retAttr.LocalName, retAttr.NamespaceURI);
+                               attr.SetDefault ();
+                               foreach (XmlNode child in retAttr.ChildNodes)
+                                       attr.AppendChild (child);
+                               this.SetNamedItem (attr);
+                       }
                        return retAttr;
                }
 
                public virtual void RemoveAll () 
                {
-                       while(Count > 0)
-                               Remove ((XmlAttribute)Nodes [0]);
+                       int current = 0;
+                       while (current < Count) {
+                               XmlAttribute attr = this [current];
+                               if (!attr.Specified)
+                                       current++;
+                               // It is called for the purpose of event support.
+                               Remove (attr);
+                       }
                }
 
                public virtual XmlAttribute RemoveAt (int i) 
@@ -253,8 +262,8 @@ namespace System.Xml
                        XmlDocumentType doctype = node.OwnerDocument.DocumentType;
                        if (doctype == null || doctype.DTD == null)
                                return existing;
-                       DTDElementDeclaration elem = doctype.DTD.ElementDecls [ownerElement.Name];
-                       DTDAttributeDefinition attdef = elem == null ? null : elem.Attributes [node.Name];
+                       DTDAttListDeclaration attList = doctype.DTD.AttListDecls [ownerElement.Name];
+                       DTDAttributeDefinition attdef = attList == null ? null : attList.Get (node.Name);
                        if (attdef == null || attdef.Datatype.TokenizedType != XmlTokenizedType.ID)
                                return existing;