2 // System.Xml.XmlAttributeCollection
5 // Jason Diamond (jason@injektilo.org)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
8 // (C) 2002 Jason Diamond http://injektilo.org/
9 // (C) 2002 Atsushi Enomoto
13 using System.Collections;
17 public class XmlAttributeCollection : XmlNamedNodeMap, ICollection
19 XmlElement ownerElement;
21 internal XmlAttributeCollection (XmlNode parent) : base (parent)
23 ownerElement = parent as XmlElement;
24 if(ownerElement == null)
25 throw new XmlException ("invalid construction for XmlAttributeCollection.");
28 bool ICollection.IsSynchronized {
30 throw new NotImplementedException ();
36 return ownerElement.IsReadOnly;
41 [System.Runtime.CompilerServices.IndexerName ("ItemOf")]
42 public virtual XmlAttribute this [string name] {
44 return (XmlAttribute) GetNamedItem (name);
49 [System.Runtime.CompilerServices.IndexerName ("ItemOf")]
50 public virtual XmlAttribute this [int i] {
52 return (XmlAttribute) Nodes [i];
57 [System.Runtime.CompilerServices.IndexerName ("ItemOf")]
58 public virtual XmlAttribute this [string localName, string namespaceURI] {
60 return (XmlAttribute) GetNamedItem (localName, namespaceURI);
64 object ICollection.SyncRoot {
66 throw new NotImplementedException ();
71 public virtual XmlAttribute Append (XmlAttribute node)
73 XmlNode xmlNode = this.SetNamedItem (node);
77 public void CopyTo (XmlAttribute[] array, int index)
79 // assuming that Nodes is a correct collection.
80 for(int i=0; i<Nodes.Count; i++)
81 array [index + i] = Nodes [i] as XmlAttribute;
84 [MonoTODO] // I don't know why this method is required...
85 void ICollection.CopyTo (Array array, int index)
87 // assuming that Nodes is a correct collection.
88 array.CopyTo (Nodes.ToArray (typeof(XmlAttribute)), index);
91 public virtual XmlAttribute InsertAfter (XmlAttribute newNode, XmlAttribute refNode)
93 if(newNode.OwnerDocument != this.ownerElement.OwnerDocument)
94 throw new ArgumentException ("different document created this newNode.");
96 ownerElement.OwnerDocument.onNodeInserting (newNode, null);
98 int pos = Nodes.Count + 1;
101 for(int i=0; i<Nodes.Count; i++)
103 XmlNode n = Nodes [i] as XmlNode;
110 if(pos > Nodes.Count)
111 throw new XmlException ("refNode not found in this collection.");
115 SetNamedItem (newNode, pos);
117 ownerElement.OwnerDocument.onNodeInserted (newNode, null);
122 public virtual XmlAttribute InsertBefore (XmlAttribute newNode, XmlAttribute refNode)
124 if(newNode.OwnerDocument != this.ownerElement.OwnerDocument)
125 throw new ArgumentException ("different document created this newNode.");
127 ownerElement.OwnerDocument.onNodeInserting (newNode, null);
129 int pos = Nodes.Count;
132 for(int i=0; i<Nodes.Count; i++)
134 XmlNode n = Nodes [i] as XmlNode;
141 if(pos == Nodes.Count)
142 throw new XmlException ("refNode not found in this collection.");
144 SetNamedItem (newNode, pos);
146 ownerElement.OwnerDocument.onNodeInserted (newNode, null);
151 public virtual XmlAttribute Prepend (XmlAttribute node)
153 return this.InsertAfter (node, null);
156 public virtual XmlAttribute Remove (XmlAttribute node)
158 if(node == null || node.OwnerDocument != this.ownerElement.OwnerDocument)
159 throw new ArgumentException ("node is null or different document created this node.");
161 XmlAttribute retAttr = null;
162 foreach(XmlAttribute attr in Nodes)
173 ownerElement.OwnerDocument.onNodeRemoving (node, null);
174 base.RemoveNamedItem (retAttr.LocalName, retAttr.NamespaceURI);
175 ownerElement.OwnerDocument.onNodeRemoved (node, null);
180 public virtual void RemoveAll ()
183 Remove ((XmlAttribute)Nodes [0]);
186 public virtual XmlAttribute RemoveAt (int i)
190 return Remove ((XmlAttribute)Nodes [i]);
193 public override XmlNode SetNamedItem (XmlNode node)
195 return SetNamedItem(node, -1);
198 [MonoTODO("event handling")]
199 internal new XmlNode SetNamedItem (XmlNode node, int pos)
202 throw new XmlException ("this AttributeCollection is read only.");
204 return base.SetNamedItem (node, pos);