Files
mono/mcs/class/System.XML/System.Xml/XmlNamedNodeMap.cs
T
Atsushi Eno 8a88d4db75 2003-03-18 Atsushi Enomoto <[email protected]>
* added XmlParserInput.cs for multi xml document sources.
	* added DTDObjectModel.cs (maybe temporary).
	* XmlTextReader.cs :
	  + fixed ctor to use XmlStreamReader. Allowed null XmlParserContext.
	  + Some members such as LineNumber, ReadChar now uses XmlParserInput.
	  + added support for Namespaces (namespace-ignorant parse available).
	  + added support for XmlResolver.
	  + replace SetReaderContext()/SetReaderFragment() with Initialize().
	  + use NameTable in CreateNameString.
	  + fixed ReadCData(). Now reads "]]]>" correctly.
	  + support for DTD parse.
	  + Read() now throws an error when it reached EOF while Depth > 0.
	* XmlAttribute.cs,
	  XmlDocumentFragment.cs,
	  XmlElement.cs : fix related to the changes of XmlTextReader.Initialize
	* XmlDocument.cs : ReadNode() now reads DocumentType.
	* XmlDocumentType.cs : implemented Entities, Notations, WriteTo().
	* XmlEntity.cs,
	  XmlNotation.cs : added override LastLinkedChild (for doctype node).
	* XmlNamedNodeMap.cs : Remove() raises an error if target is read only.
	* XmlElement.cs : bugfix for node removal of set_InnerXml.
	* XmlNode.cs : added insertBeforeIntern() derived from InsertBefore().
	  (to append child XmlEntity into XmlDocumentType correctly.)
	* XmlInputStream.cs : fixed to access file with FileAccess.Read.

svn path=/trunk/mcs/; revision=12619
2003-03-17 16:01:36 +00:00

116 lines
2.4 KiB
C#

//
// System.Xml.XmlNamedNodeMap
//
// Author:
// Jason Diamond ([email protected])
// Duncan Mak ([email protected])
//
// (C) 2002 Jason Diamond http://injektilo.org/
//
using System;
using System.Collections;
namespace System.Xml
{
public class XmlNamedNodeMap : IEnumerable
{
XmlNode parent;
ArrayList nodeList;
bool readOnly = false;
internal XmlNamedNodeMap (XmlNode parent)
{
this.parent = parent;
nodeList = new ArrayList ();
}
public virtual int Count {
get { return nodeList.Count; }
}
public virtual IEnumerator GetEnumerator ()
{
return nodeList.GetEnumerator ();
}
public virtual XmlNode GetNamedItem (string name)
{
foreach (XmlNode node in nodeList) {
if (node.Name == name)
return node;
}
return null;
}
public virtual XmlNode GetNamedItem (string localName, string namespaceURI)
{
foreach (XmlNode node in nodeList) {
if ((node.LocalName == localName)
&& (node.NamespaceURI == namespaceURI))
return node;
}
return null;
}
public virtual XmlNode Item (int index)
{
if (index < 0 || index > nodeList.Count)
return null;
else
return (XmlNode) nodeList [index];
}
public virtual XmlNode RemoveNamedItem (string name)
{
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;
}
public virtual XmlNode RemoveNamedItem (string localName, string namespaceURI)
{
foreach (XmlNode node in nodeList)
if ((node.LocalName == localName)
&& (node.NamespaceURI == namespaceURI)) {
nodeList.Remove (node);
return node;
}
return null;
}
public virtual XmlNode SetNamedItem (XmlNode 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; } }
}
}