X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml%2FXmlNamedNodeMap.cs;h=b588fb19edb987c390f096b974a0f3ac78ee5704;hb=5fc9c2af02a107978ae47db87fe0a4d6f6a3bcd9;hp=97606e73f7b4b885edc17f925ac2a21994e9ec07;hpb=b85325090c44995ea0a8155ef09aef8caac8520d;p=mono.git diff --git a/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs b/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs index 97606e73f7b..b588fb19edb 100644 --- a/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs +++ b/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs @@ -3,6 +3,7 @@ // // Author: // Jason Diamond (jason@injektilo.org) +// Duncan Mak (duncan@ximian.com) // // (C) 2002 Jason Diamond http://injektilo.org/ // @@ -14,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) { @@ -23,59 +25,91 @@ namespace System.Xml nodeList = new ArrayList (); } - [MonoTODO] public virtual int Count { - get { - throw new NotImplementedException (); - } + get { return nodeList.Count; } } - [MonoTODO] public virtual IEnumerator GetEnumerator () { - throw new NotImplementedException (); + return nodeList.GetEnumerator (); } - [MonoTODO] public virtual XmlNode GetNamedItem (string name) { foreach (XmlNode node in nodeList) { if (node.Name == name) return node; } - return null; } - [MonoTODO] public virtual XmlNode GetNamedItem (string localName, string namespaceURI) { - throw new NotImplementedException (); - } + foreach (XmlNode node in nodeList) { + if ((node.LocalName == localName) + && (node.NamespaceURI == namespaceURI)) + return node; + } - [MonoTODO] + return null; + } + public virtual XmlNode Item (int index) { - throw new NotImplementedException (); + if (index < 0 || index > nodeList.Count) + return null; + else + return (XmlNode) nodeList [index]; } - [MonoTODO] public virtual XmlNode RemoveNamedItem (string name) - { - throw new NotImplementedException (); + { + foreach (XmlNode node in nodeList) + if (node.Name == name) { + if (node.IsReadOnly) + throw new InvalidOperationException ("Cannot remove. This node is read only: " + 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.LocalName == localName) + && (node.NamespaceURI == namespaceURI)) { + nodeList.Remove (node); + return node; + } + + return null; } - [MonoTODO] public virtual XmlNode SetNamedItem (XmlNode node) { - nodeList.Add (node); - return node; + return SetNamedItem(node, -1); + } + + internal XmlNode SetNamedItem (XmlNode node, int pos) + { + if (readOnly || (node.OwnerDocument != parent.OwnerDocument)) + throw new ArgumentException ("Cannot add to NodeMap."); + + foreach (XmlNode x in nodeList) + if(x.LocalName == node.LocalName && x.NamespaceURI == node.NamespaceURI) { + nodeList.Remove (x); + nodeList.Add (node); + return x; + } + + if(pos < 0) + nodeList.Add (node); + else + nodeList.Insert(pos, node); + return null; } + + internal ArrayList Nodes { get { return nodeList; } } } }