rewrote XmlNode with touchups to XmlDocument, XmlElement, and XmlLinkedNode
authorKral Ferch <kral@mono-cvs.ximian.com>
Thu, 7 Mar 2002 02:32:39 +0000 (02:32 -0000)
committerKral Ferch <kral@mono-cvs.ximian.com>
Thu, 7 Mar 2002 02:32:39 +0000 (02:32 -0000)
svn path=/trunk/mcs/; revision=2954

13 files changed:
mcs/class/System.XML/Mono.System.XML.csproj
mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlComment.cs
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlElement.cs
mcs/class/System.XML/System.Xml/XmlLinkedNode.cs
mcs/class/System.XML/System.Xml/XmlNode.cs
mcs/class/System.XML/System.Xml/XmlProcessingInstruction.cs
mcs/class/System.XML/Test/ChangeLog
mcs/class/System.XML/Test/Microsoft.Test.csproj
mcs/class/System.XML/Test/Mono.Test.csproj
mcs/class/System.XML/Test/XmlAttributeTests.cs
mcs/class/System.XML/Test/XmlDocumentTests.cs

index ed4b1b3af0a3f16f4264a223e8f42f03c753250d..0f6d167cbadb6b21067bce3c3c6a3e5772e30e64 100644 (file)
         </Build>
         <Files>
             <Include>
+                <File
+                    RelPath = "System.Xml\ChangeLog"
+                    BuildAction = "None"
+                />
                 <File
                     RelPath = "System.Xml\DomEncodingType.cs"
                     SubType = "Code"
index eb1387c397376afe527fd8457be75e8623da5d77..d1a7df66a7ca113a6b4ce290a9fd26ff16033aea 100644 (file)
@@ -1,3 +1,18 @@
+2002-03-06  Kral Ferch <kral_ferch@hotmail.com>
+
+       * XmlNode.cs: Rewrote this class from scratch with
+       MonoToDo attribs and NotImplementedExceptions.  Now defines an
+       internal LastLinkedNode property to aid the new implementation.
+       XmlNodes only have ref to owner doc and parent nodes now.
+       
+       * XmlLinkedNode.cs: Added NextLinkedSibling internal property
+       and ref to next sibling to support walking our circular child
+       node list.
+       
+       * XmlDocument.cs: Added ref to last child node and overrides
+       XmlNode's internal LastLinkedChild property to support walking
+       our circular child node list.
+       
 2002-03-02  Kral Ferch <kral_ferch@hotmail.com>
 
        * XmlProcessingInstructions.cs: Class was empty.  Implemented
index 92a73d017afca49a3066c2949a38610d4179d9d2..aed7777f9b2aa026cd6954e41c7256b91ba75593 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Xml
 
                public override XmlNode CloneNode(bool deep)
                {
-                       return new XmlComment(Value, FOwnerDocument);
+                       return new XmlComment(Value, OwnerDocument);
                }
 
                [MonoTODO]
index b674a6e5bad19e6144147481dfaa40d7f627cad5..987112960e714f0a214ad8b8922f92cea36bfbdc 100644 (file)
@@ -16,12 +16,15 @@ namespace System.Xml
 
        public class XmlDocument : XmlNode
        {
+               #region Fields
+
+               private XmlLinkedNode lastChild;
+
+               #endregion
+
                #region Constructors
 
-               public XmlDocument () : base (null)
-               {
-                       FOwnerDocument = this;
-               }
+               public XmlDocument () : base (null) { }
 
                [MonoTODO]
                protected internal XmlDocument (XmlImplementation imp) : base (null)
@@ -57,9 +60,7 @@ namespace System.Xml
 
                [MonoTODO]
                public override string BaseURI {
-                       get {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
                }
 
                public XmlElement DocumentElement {
@@ -78,82 +79,87 @@ namespace System.Xml
 
                [MonoTODO]
                public virtual XmlDocumentType DocumentType {
-                       get {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
                }
 
                [MonoTODO]
                public XmlImplementation Implementation {
-                       get {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
                }
 
                [MonoTODO]
                public override string InnerXml {
-                       get {
-                               throw new NotImplementedException();
-                       }
-
-                       set {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
+                       set { throw new NotImplementedException(); }
                }
 
                public override bool IsReadOnly {
-                       get { 
-                               return false; 
-                       }
+                       get { return false; }
                }
 
-               public override string LocalName {
-                       get { 
-                               return "#document"; 
+               internal override XmlLinkedNode LastLinkedChild
+               {
+                       get     {
+                               return lastChild;
+                       }
+                       /// set'er Should only be called by XmlNode.AppendChild().
+                       set 
+                       {
+                               // This is our special case for clearing out all children.
+                               // XmlNode.RemoveAll() will call this method passing in
+                               // a null node.
+                               if (value == null)
+                               {
+                                       // This should allow the GC to collect up our circular list
+                                       // that we no longer have a reference to.
+                                       lastChild = null;
+                                       return;
+                               }
+
+                               if (LastChild == null) 
+                               {
+                                       lastChild = value;
+                                       LastLinkedChild.NextLinkedSibling = null;
+                               }
+                               
+                               value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling;
+                               LastLinkedChild.NextLinkedSibling = value;
+
+                               SetParentNode(this);
                        }
                }
+               
+               public override string LocalName 
+               {
+                       get { return "#document"; }
+               }
 
                public override string Name {
-                       get { 
-                               return "#document"; 
-                       }
+                       get { return "#document"; }
                }
 
                [MonoTODO]
                public XmlNameTable NameTable {
-                       get {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
                }
 
                public override XmlNodeType NodeType {
-                       get { 
-                               return XmlNodeType.Document; 
-                       }
+                       get { return XmlNodeType.Document; }
                }
 
                public override XmlDocument OwnerDocument {
-                       get { 
-                               return null; 
-                       }
+                       get { return null; }
                }
 
                [MonoTODO]
                public bool PreserveWhitespace {
-                       get {
-                               throw new NotImplementedException();
-                       }
-
-                       set {
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException(); }
+                       set { throw new NotImplementedException(); }
                }
 
                [MonoTODO]
                public XmlResolver XmlResolver {
-                       set {
-                               throw new NotImplementedException();
-                       }
+                       set { throw new NotImplementedException(); }
                }
 
                #endregion
@@ -194,7 +200,6 @@ namespace System.Xml
                        return CreateAttribute (prefix, localName, String.Empty);
                }
 
-               [MonoTODO]
                public virtual XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI)
                {
                        return new XmlAttribute (prefix, localName, namespaceURI, this);
index b98235f990ccb2b30b9bd0f4a10a072fca264592..857517c24f4532734dac8fd556f9ab46b564ad3d 100644 (file)
@@ -16,6 +16,7 @@ namespace System.Xml
                #region Fields
 
                private XmlAttributeCollection attributes;
+               private XmlLinkedNode lastChild;
                private string localName;
                private string namespaceURI;
                private string prefix;
@@ -86,7 +87,41 @@ namespace System.Xml
                        }
                }
 
-               public override string LocalName {
+               internal override XmlLinkedNode LastLinkedChild
+               {
+                       get     
+                       {
+                               return lastChild;
+                       }
+                       /// set'er Should only be called by XmlNode.AppendChild().
+                       set 
+                       {
+                               // This is our special case for clearing out all children.
+                               // XmlNode.RemoveAll() will call this method passing in
+                               // a null node.
+                               if (value == null)
+                               {
+                                       // This should allow the GC to collect up our circular list
+                                       // that we no longer have a reference to.
+                                       lastChild = null;
+                                       return;
+                               }
+
+                               if (LastChild == null) 
+                               {
+                                       lastChild = value;
+                                       LastLinkedChild.NextLinkedSibling = null;
+                               }
+                               
+                               value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling;
+                               LastLinkedChild.NextLinkedSibling = value;
+
+                               SetParentNode(this);
+                       }
+               }
+               
+               public override string LocalName 
+               {
                        get { 
                                return localName; 
                        }
index f577d694c707817d1220dfaf2d3e26ecd3b709f2..e1675724e6ccf77793c95c70718ef6d261bfdc44 100644 (file)
@@ -4,6 +4,8 @@ namespace System.Xml
 {
        public abstract class XmlLinkedNode : XmlNode
        {
+               XmlLinkedNode nextSibling;
+
                #region Constructors
 
                protected internal XmlLinkedNode(XmlDocument doc) : base(doc) { }
@@ -12,14 +14,24 @@ namespace System.Xml
 
                #region Properties
 
-               [MonoTODO]
                public override XmlNode NextSibling
                {
                        get {
-                               throw new NotImplementedException ();
+                               if (Object.ReferenceEquals(nextSibling, ParentNode.LastLinkedChild.NextLinkedSibling) == false) {
+                                       return nextSibling;
+                               }
+                               else {
+                                       return null;
+                               }
                        }
                }
 
+               internal XmlLinkedNode NextLinkedSibling
+               {
+                       get { return nextSibling; }
+                       set { nextSibling = value; }
+               }
+
                [MonoTODO]
                public override XmlNode PreviousSibling
                {
@@ -29,5 +41,6 @@ namespace System.Xml
                }
 
                #endregion
+
        }
 }
\ No newline at end of file
index 455bb50036883d01e977a5a2d00e9a5995499623..bfe9a942761d5bfb809c86eecf380a373edcb663 100644 (file)
-// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 //
-// System.Xml.XmlNode
+// System.Xml.XmlProcessingInstruction
 //
 // Author:
-//   Daniel Weber (daniel-weber@austin.rr.com)
+//   Kral Ferch <kral_ferch@hotmail.com>
+//
+// (C) 2002 Kral Ferch
 //
-// (C) 2001 Daniel Weber
 
 using System;
 using System.Collections;
 using System.Xml.XPath;
 
-namespace System.Xml 
+namespace System.Xml
 {
-       public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable 
+       public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
        {
-               //======= Private data members ==============================================
-               private XmlNodeListAsArrayList _childNodes;
-               protected XmlDocument FOwnerDocument;
-               protected XmlNode _parent;
-
-               // Names of node
-               // for <foo:bar xmlns:foo="http://www.foobar.com/schema/foobar">... </foo:bar>
-               //      qualified name: foo:bar
-               //      namespaceURI = "http://www.foobar.com/schema/foobar"
-               //  localName = bar
-               //      prefix = foo
-               // Note that namespaces can be nested (child namespace != parent namespace)
-               // namespaces are optional
-               protected string Fname;
-               protected string FnamespaceURI;
-               protected string Fprefix;
-               protected string FlocalName;
-
-               // baseURI holds the location from which the document was loaded
-               // If the node was created from a document at c:\tmp.xml, then that's what will be here
-               protected string FbaseURI;
-
-               // value of the node (overriden in classes that do something different)
-               //      default behavior is just to store it
-               protected string Fvalue;
-               
-               //=====================================================================
-               // ============ Properties ============================================
-               //=====================================================================
-               /// <summary>
-               /// Get the XmlAttributeCollection representing the attributes
-               ///   on the node type.  Returns null if the node type is not XmlElement.
-               /// </summary>
-               public virtual XmlAttributeCollection Attributes 
-               {
-                       get 
-                       {
-                               return null;
-                       }
-               }
-               /// <summary>
-               ///  Return the base Uniform Resource Indicator (URI) used to resolve
-               ///  this node, or String.Empty.
-               /// </summary>
-               public virtual string BaseURI 
+               XmlDocument ownerDocument;
+               XmlNode parentNode;
+
+               #region Constructors
+
+               protected internal XmlNode(XmlDocument ownerDocument)
                {
-                       get 
-                       {
-                               return FbaseURI;
-                       }
+                       this.ownerDocument = ownerDocument;
+               }
 
+               #endregion
+
+               #region Properties
+
+               public virtual XmlAttributeCollection Attributes
+               {
+                       get { return null; }
                }
-               /// <summary>
-               /// Return all child nodes of this node.  If there are no children,
-               ///  return an empty XmlNodeList;
-               /// </summary>
-               public virtual XmlNodeList ChildNodes 
+
+               [MonoTODO]
+               public virtual string BaseURI
                {
-                       get 
-                       {
-                               if (_childNodes == null)
-                                       _childNodes = new XmlNodeListAsArrayList();
+                       get { throw new NotImplementedException (); }
+               }
 
-                               return _childNodes as XmlNodeList;
-                       }
+               [MonoTODO]
+               public virtual XmlNodeList ChildNodes
+               {
+                       get { throw new NotImplementedException (); }
                }
-               
-               /// <summary>
-               /// Return first child node as XmlNode or null
-               /// if the node has no children
-               /// </summary>
-               public virtual XmlNode FirstChild 
+
+               public virtual XmlNode FirstChild
                {
-                       get
-                       {
-                               if (ChildNodes.Count == 0)
+                       get {
+                               if (LastChild != null) {
+                                       return LastLinkedChild.NextLinkedSibling;
+                               }
+                               else {
                                        return null;
-                               else
-                                       return ChildNodes[0];
+                               }
                        }
                }
 
-               /// <summary>
-               ///             Return true if the node has children
-               /// </summary>
-               public virtual bool HasChildNodes 
+               public virtual bool HasChildNodes
                {
-                       get 
-                       {
-                               if (ChildNodes.Count == 0)
-                                       return true;
-                               else
-                                       return false;
-                       }
+                       get { return LastChild != null; }
                }
 
-               /// <summary>
-               /// Get or Set the concatenated values of node and children
-               /// </summary>
+               [MonoTODO]
                public virtual string InnerText
                {
-                       get
-                       {
-                               // TODO - implement set InnerText()
-                               throw new NotImplementedException();
-                       }
-
-                       set 
-                       {
-                               // TODO - implement set InnerText()
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Get/Set the XML representing just the child nodes of this node
-               /// </summary>
+               [MonoTODO]
                public virtual string InnerXml
                {
-                       get
-                       {
-                               // TODO - implement set InnerXml()
-                               throw new NotImplementedException();
-                       }
-
-                       set 
-                       {
-                               // TODO - implement set InnerXml()
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Property Get - true if node is read-only
-               /// </summary>
+               [MonoTODO]
                public virtual bool IsReadOnly
                {
-                       get
-                       {
-                               return OwnerDocument.IsReadOnly;
-                       }
+                       get { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Return the child element named [string].  Returns XmlElement
-               /// Indexer for XmlNode class.
-               /// </summary>
-               [System.Runtime.CompilerServices.IndexerNameAttribute("Item")]
-               public virtual XmlElement this [String index]
+               [MonoTODO]
+               public virtual XmlElement this[string name]
                {
-                       get 
-                       {
-                               // TODO - implement XmlNode.Item(string)
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public virtual XmlElement this[string localname, string ns]
+               {
+                       get { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Get the last child node, or null if there are no nodes
-               /// </summary>
                public virtual XmlNode LastChild
                {
-                       get
-                       {
-                if (_childNodes.Count == 0)
-                                return null;
-                               else
-                                return _childNodes.Item(_childNodes.Count - 1);
-                       }
+                       get { return LastLinkedChild; }
+               }
 
+               internal virtual XmlLinkedNode LastLinkedChild
+               {
+                       get { return null; }
+                       set { }
                }
 
-               /// <summary>
-               /// Returns the local name of the node with qualifiers removed
-               /// LocalName of ns:elementName = "elementName"
-               /// </summary>
-               public abstract string LocalName {get;}
+               [MonoTODO]
+               public abstract string LocalName
+               {
+                       get;
+               }
 
-               /// <summary>
-               /// Get the qualified node name
-               /// derived classes must implement as behavior varies
-               /// by tag type.
-               /// </summary>
-               public abstract string Name { get; }
+               [MonoTODO]
+               public abstract string Name
+               {
+                       get;
+               }
 
-               /// <summary>
-               /// Get the namespace URI or String.Empty if none
-               /// </summary>
+               [MonoTODO]
                public virtual string NamespaceURI
                {
-                       get
-                       {
-                               // TODO - implement Namespace URI, or determine abstractness
-                               throw new NotImplementedException("XmlNode.NamespaceURI not implemented");
-                       }
+                       get { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Get the node immediatelly following this node, or null
-               /// </summary>
-               public virtual XmlNode NextSibling 
+               public virtual XmlNode NextSibling
                {
-                       get
-                       {
-                               
-                               if (_parent != null)
-                               {
-                                       XmlNodeListAsArrayList children = _parent.ChildNodes as XmlNodeListAsArrayList;
-                                       int ourIndex = children.data.IndexOf(this);
-                                       return children[ourIndex + 1];
-                               }
-                               else
-                                       return null;
-                       }
+                       get { return null; }
                }
 
-               public virtual XmlNodeType NodeType 
+               [MonoTODO]
+               public abstract XmlNodeType NodeType
                {
-                       get
-                       {
-                               return XmlNodeType.None;
-                       }
+                       get;
                }
 
-               /// <summary>
-               /// Return the string representing this node and all it's children
-               /// </summary>
+               [MonoTODO]
                public virtual string OuterXml
                {
-                       get
-                       {
-                               // TODO - implement OuterXml {get;}
-                               throw new NotImplementedException();
-                       }
+                       get { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Return owning document.
-               /// If this nodeType is a document, return null
-               /// </summary>
                public virtual XmlDocument OwnerDocument
                {
-                       get
-                       {
-                               return FOwnerDocument;
-                       }
+                       get { return ownerDocument; }
                }
 
-               /// <summary>
-               /// Returns the parent node, or null
-               /// Return value depends on superclass node type
-               /// </summary>
                public virtual XmlNode ParentNode
                {
-                       get
-                       {
-                               return _parent;
-                       }
+                       get { return parentNode; }
                }
-               
-               /// <summary>
-               /// set/get the namespace prefix for this node, or 
-               /// string.empty if it does not exist
-               /// </summary>
-               public virtual string Prefix 
+
+               [MonoTODO]
+               public virtual string Prefix
                {
-                       get
-                       {
-                               return Fprefix;
-                       }
-                       
-                       set
-                       {
-                               // TODO - validation on XmlNode.Prefix {set;}? (no)
-                               Fprefix = value;
-                       }
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// The preceding XmlNode or null
-               /// </summary>
-               public virtual XmlNode PreviousSibling {
-                       get
-                       {
-                               if (_parent != null)
-                               {
-                                       XmlNodeListAsArrayList children = _parent.ChildNodes as XmlNodeListAsArrayList;
-                                       int ourIndex = children.data.IndexOf(this);
-                                       return children[ourIndex - 1];
-                               }
-                               else
-                                       return null;
-                       }
+               public virtual XmlNode PreviousSibling
+               {
+                       get { return null; }
+               }
+
+               [MonoTODO]
+               public virtual string Value
+               {
+                       get { throw new NotImplementedException (); }
+                       set { throw new NotImplementedException (); }
                }
 
-               /// <summary>
-               /// Get/Set the value for this node
-               /// </summary>
-               public virtual string Value 
+               #endregion
+
+               #region Methods
+
+               public virtual XmlNode AppendChild (XmlNode newChild)
                {
-                       get
-                       {
-                               return Fvalue;
+                       if ((NodeType == XmlNodeType.Document) || (NodeType == XmlNodeType.Element)) {
+                               LastLinkedChild = (XmlLinkedNode) newChild;
+                               return LastChild;
                        }
-                       
-                       set
-                       {
-                               Fvalue = value;
+                       else {
+                               throw new InvalidOperationException();
                        }
                }
 
-               //=====================================================================
-               //======= Methods =====================================================
-               //=====================================================================
-               /// <summary>
-               /// Appends the specified node to the end of the child node list
-               /// </summary>
-               /// <param name="newChild"></param>
-               /// <returns></returns>
-               public virtual XmlNode AppendChild (XmlNode newChild)
+               [MonoTODO]
+               public virtual XmlNode Clone ()
                {
-                       ((XmlNodeListAsArrayList)ChildNodes).Add(newChild);
-                       return newChild;
-               }
-
-               /// <summary>
-               /// Return a clone of this node
-               /// </summary>
-               /// <returns></returns>
-               public virtual object Clone()
-               {
-                       // TODO - implement XmlNode.Clone() as object
-                       throw new NotImplementedException("object XmlNode.Clone() not implmented");
-               }
-
-               /// <summary>
-               /// Return a clone of the node
-               /// </summary>
-               /// <param name="deep">Make copy of all children</param>
-               /// <returns>Cloned node</returns>
-               public abstract XmlNode CloneNode( bool deep);
-
-               /// <summary>
-               /// Return an XPathNavigator for navigating this node
-               /// </summary>
-               /// <returns></returns>
-               public System.Xml.XPath.XPathNavigator CreateNavigator()
-               {
-                       // TODO - implement CreateNavigator()
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Provide support for "for each" 
-               /// </summary>
-               /// <returns></returns>
-               public IEnumerator GetEnumerator()
-               {
-                       return _childNodes.data.GetEnumerator();
-               }
-
-               /// <summary>
-               /// Look up the closest namespace for this node that is in scope for the given prefix
-               /// </summary>
-               /// <param name="prefix"></param>
-               /// <returns>Namespace URI</returns>
-               public virtual string GetNamespaceOfPrefix(string prefix)
-               {
-                       // TODO - implement GetNamespaceOfPrefix()
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Get the closest xmlns declaration for the given namespace URI that is in scope.
-               /// Returns the prefix defined in that declaration.
-               /// </summary>
-               /// <param name="namespaceURI"></param>
-               /// <returns></returns>
-               public virtual string GetPrefixOfNamespace(string namespaceURI)
-               {
-                       // TODO - implement GetPrefixOfNamespace
-                       throw new NotImplementedException();
-               }
-               
-               /// <summary>
-               /// Insert newChild directly after the reference node.
-               /// If refChild is null, newChild is inserted at the beginning of childnodes.
-               /// If newChild is a document fragment, all nodes are inserted after refChild.
-               /// If newChild is already in the tree, it is first removed.
-               /// </summary>
-               /// <exception cref="ArgumentException">NewChild was created from differant document.
-               /// RefChild not a child of this node or null.
-               /// Node is read-only</exception>
-               /// <exception cref="InvalidOperationException">Node is of type that does not have children
-               /// Node to insert is an ancestor of this node.</exception>
-               /// <param name="newChild">Child node to insert.</param>
-               /// <param name="refChild">Reference node to insert after</param>
-               /// <returns>Removed node, or null if no node removed.</returns>
-               public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
-               {
-                       // Checks parent not ancestor, arguments valid, etc.  Throws exception on error
-                       InsertionCheck(newChild, refChild);
-
-                       // Scan the node list, looking for refChild and seeing if newChild is in the list
-                       // Note that if refNode is null (prepend), we don't want to do the .Equals(null)
-                       XmlNode retval = null;
-                       int refNodeIndex = -1;
-                       
-                       for (int i = 0; i < _childNodes.Count; i++)
-                       {
-                               XmlNode e = _childNodes.data[i] as XmlNode;
-                               if (e.Equals(newChild))
-                               {
-                                       retval = e;
-                                       FOwnerDocument.onNodeRemoving(newChild, newChild.ParentNode);
-                                       _childNodes.data.RemoveAt(i);
-                                       newChild.setParent(null);
-                                       FOwnerDocument.onNodeRemoved(newChild, null);
-                                       break;
-               
-                               }
+                       throw new NotImplementedException ();
+               }
 
-                               if ( (refChild != null ) & ( e.Equals(refChild) ) )
-                               {
-                                       refNodeIndex = i;
+               public abstract XmlNode CloneNode (bool deep);
 
-                                       if (retval != null)
-                                               break;
-                               }
-                       }
+               [MonoTODO]
+               public XPathNavigator CreateNavigator ()
+               {
+                       throw new NotImplementedException ();
+               }
 
-                       if ( ( refNodeIndex == -1 ) & (refChild != null) )
-                               throw new ArgumentException("Reference node not found (and not null) in call to XmlNode.InsertAfter()");
-
-                       FOwnerDocument.onNodeInserting(newChild, this);
-
-                       if (refChild == null)
-                               refNodeIndex = 0;
-                       else
-                               refNodeIndex++;                 // insert after reference...
-
-                       if (newChild.NodeType == XmlNodeType.DocumentFragment)
-                       {
-                               // Insert all children, starting from refNodeIndex (0,1,2...n)
-                               for (int i = 0; i < newChild.ChildNodes.Count; i++)
-                               {
-                                       XmlNode e = newChild.ChildNodes[i] as XmlNode;
-                                       FOwnerDocument.onNodeInserting(e, this);
-                                       _childNodes.data.Insert(refNodeIndex, newChild.ChildNodes[i]);
-                                       e.setParent(this);
-                                       FOwnerDocument.onNodeInserted(newChild, this);
-                                       refNodeIndex ++;
-                               }
-                       }
-                       else
-                       {
-                               FOwnerDocument.onNodeInserting(newChild, this);
-                               _childNodes.data.Insert(refNodeIndex, newChild);
-                               newChild.setParent(this);
-                               FOwnerDocument.onNodeInserted(newChild, this);
-                       }
+               [MonoTODO]
+               public IEnumerator GetEnumerator ()
+               {
+                       throw new NotImplementedException ();
+               }
 
-                       return retval;
-               }
-               
-               /// <summary>
-               /// Insert newChild directly before the reference node.
-               /// If refChild is null, newChild is inserted at the end of childnodes.
-               /// If newChild is a document fragment, all nodes are inserted before refChild.
-               /// If newChild is already in the tree, it is first removed.
-               /// </summary>
-               /// <exception cref="ArgumentException">NewChild was created from different document.
-               /// RefChild not a child of this node, or is null.
-               /// Node is read-only</exception>
-               /// <exception cref="InvalidOperationException">Node is of type that does not have children.
-               /// Node to insert is an ancestor of this node.</exception>
-               /// <param name="newChild">Child node to insert.</param>
-               /// <param name="refChild">Reference node to insert after</param>
-               /// <returns>Removed node, or null if no node removed.</returns>
-               public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
-               {
-                       // Checks parent not ancestor, arguments valid, etc.  Throws exception on error
-                       InsertionCheck(newChild, refChild);
-
-                       // Scan the node list, looking for refChild and seeing if newChild is in the list
-                       XmlNode retval = null;
-                       int refNodeIndex = -1;
-                       
-                       for (int i = 0; i < _childNodes.Count; i++)
-                       {
-                               XmlNode e = _childNodes.data[i] as XmlNode;
-                               if (e.Equals(newChild))
-                               {
-                                       retval = e;
-                                       FOwnerDocument.onNodeRemoving(newChild, newChild.ParentNode);
-                                       _childNodes.data.RemoveAt(i);
-                                       newChild.setParent(null);
-                                       FOwnerDocument.onNodeRemoved(newChild, null);
-                                       break;
-                               }
+               [MonoTODO]
+               public virtual string GetNamespaceOfPrefix (string prefix)
+               {
+                       throw new NotImplementedException ();
+               }
 
-                               if ( (refChild != null ) & ( e.Equals(refChild) ) )
-                               {
-                                       refNodeIndex = i;
+               [MonoTODO]
+               public virtual string GetPrefixOfNamespace (string namespaceURI)
+               {
+                       throw new NotImplementedException ();
+               }
 
-                                       if (retval != null)
-                                               break;
-                               }
-                       }
+               object ICloneable.Clone ()
+               {
+                       return Clone ();
+               }
 
-                       if ( ( refNodeIndex == -1 ) & (refChild != null) )
-                               throw new ArgumentException("Reference node not found (and not null) in call to XmlNode.InsertAfter()");
-
-                       if (refChild == null)
-                               refNodeIndex = _childNodes.Count;
-
-                       if (newChild.NodeType == XmlNodeType.DocumentFragment)
-                       {
-                               // Insert all children, starting from refNodeIndex (0,1,2...n)
-                               for (int i = 0; i < newChild.ChildNodes.Count; i++)
-                               {
-                                       XmlNode e = newChild.ChildNodes[i] as XmlNode;
-                                       FOwnerDocument.onNodeInserting(e, this);
-                                       _childNodes.data.Insert(refNodeIndex, newChild.ChildNodes[i]);
-                                       e.setParent(this);
-                                       FOwnerDocument.onNodeInserted(newChild, this);
-                                       refNodeIndex ++;
-                               }
-                       }
-                       else
-                       {
-                               newChild.OwnerDocument.onNodeInserting(newChild, this);
-                               _childNodes.data.Insert(refNodeIndex, newChild);
-                               newChild.setParent(this);
-                               newChild.OwnerDocument.onNodeInserted(newChild, this);
-                       }
+               IEnumerator IEnumerable.GetEnumerator ()
+               {
+                       return GetEnumerator ();
+               }
 
-                       return retval;
+               [MonoTODO]
+               public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
+               {
+                       throw new NotImplementedException ();
                }
 
-               /// <summary>
-               /// Put all nodes under this node in "normal" form
-               /// Whatever that means...
-               /// </summary>
-               public virtual void Normalize()
+               [MonoTODO]
+               public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
                {
-                       // TODO - Implement Normalize()
-                       throw new NotImplementedException();
+                       throw new NotImplementedException ();
                }
 
-               /// <summary>
-               /// Add the specified child to the beginning of the child node list
-               /// </summary>
-               /// <param name="newChild">Node to add</param>
-               /// <returns>The node added</returns>
-               public virtual XmlNode PrependChild(XmlNode newChild)
+               [MonoTODO]
+               public virtual void Normalize ()
                {
-                       return InsertAfter(newChild, null);
+                       throw new NotImplementedException ();
                }
 
-               /// <summary>
-               /// Remove all children and attributes
-               /// </summary>
-               public virtual void RemoveAll()
+               [MonoTODO]
+               public virtual XmlNode PrependChild (XmlNode newChild)
                {
-                       if (_childNodes == null)
-                               return;
-                       else
-                       {
-                               // Remove in order, 0..n
-                               while (_childNodes.Count > 0)
-                               {
-                                       XmlNode e = _childNodes[0];
-                                       FOwnerDocument.onNodeRemoving(e, this);
-                                       e.setParent(null);
-                                       _childNodes.data.RemoveAt(0);
-                                       FOwnerDocument.onNodeRemoved(e, null);
-                               }
-                       }
+                       throw new NotImplementedException ();
                }
 
-               /// <summary>
-               /// Remove specified child node
-               /// </summary>
-               /// <param name="oldChild"></param>
-               /// <returns>Removed node</returns>
-               public virtual XmlNode RemoveChild(XmlNode oldChild)
+               public virtual void RemoveAll ()
                {
-                       // TODO - implement RemoveChild(oldChild)
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Select a list of nodes matching the xpath
-               /// </summary>
-               /// <param name="xpath"></param>
-               /// <returns>matching nodes</returns>
-               public XmlNodeList SelectNodes( string xpath)
-               {
-                       // TODO - imlement SelectNodes(xpath)
-                       throw new NotImplementedException();
+                       LastLinkedChild = null;
                }
-
-               /// <summary>
-               /// Select a list of nodes matching the xpath.  Any prefixes are resolved
-               /// using the passed namespace manager
-               /// </summary>
-               /// <param name="xpath"></param>
-               /// <param name="nsmgr"></param>
-               /// <returns></returns>
-               public XmlNodeList SelectNodes(string xpath, XmlNamespaceManager nsmgr)
-               {
-                       // TODO - implement SelectNodes(xpath, nsmgr)
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Selects the first node that matches xpath
-               /// </summary>
-               /// <param name="?"></param>
-               /// <returns></returns>
-               public XmlNode SelectSingleNode(string xpatch)
-               {
-                       // TODO - implement SelectSingeNode(xpath)
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Returns the first node that matches xpath
-               /// Uses the passed namespace manager to resolve namespace URI's
-               /// </summary>
-               /// <param name="xpath"></param>
-               /// <param name="nsmgr"></param>
-               /// <returns></returns>
-               public XmlNode SelectSingleNode(string xpath, XmlNamespaceManager nsmgr)
-               {
-                       // Implement SelectSingleNode(xpath, nsmgr)
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Tests if the DOM implementation supports the passed feature
-               /// </summary>
-               /// <param name="feature"></param>
-               /// <param name="version"></param>
-               /// <returns></returns>
-               public virtual bool Supports(string feature, string version)
-               {
-                       //TODO - implement Supports(feature, version)
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Returns a string representation of the current node and it's children
-               /// </summary>
-               /// <returns></returns>
-               public override string ToString()
-               {
-                       // TODO - implement ToString()
-                       throw new NotImplementedException();
-               }
-
-               /// <summary>
-               /// Saves all children of the current node to the passed writer
-               /// </summary>
-               /// <param name="w"></param>
-               public abstract void WriteContentTo(XmlWriter w);
-               
-               /// <summary>
-               /// Saves the current node to writer w
-               /// </summary>
-               /// <param name="w"></param>
-               public abstract void WriteTo(XmlWriter w);
-
-               //======= Internal methods    ===============================================
-               /// <summary>
-               /// accessor {set;} for parentNode only visible internally.
-               /// </summary>
-               /// <param name="newParent">new parent node.</param>
-               internal void setParent( XmlNode newParent)
-               {
-                       _parent = newParent;
-               }
-               
-               //======= Protected methods    ==============================================
-
-               //======= Private Methods ===================================================
-               /// <summary>
-               /// Helper function to perform checks required before insrting a node.
-               /// Throws applicable exceptions on error.
-               /// </summary>
-               /// <param name="newChild"></param>
-               /// <param name="refChild"></param>
-               private void InsertionCheck( XmlNode newChild, XmlNode refChild)
-               {
-                       if (newChild == null)
-                               throw new ArgumentNullException("Null newNode passed to InsertAfter()");
-
-                       if (newChild.Equals(this))
-                               throw new ArgumentException("Cannot insert node onto itself");
-
-                       if (NodeType != XmlNodeType.Document && !FOwnerDocument.Equals( newChild.OwnerDocument) )
-                               throw new ArgumentException("Reference node has different owner document than this node");
-               
-                       XmlDocument ownerDocument = newChild.OwnerDocument;
-
-                       if (ownerDocument.IsReadOnly )
-                               throw new ArgumentException("Operation not supported - tree is read-only");
-
-                       //Check that insert node is not in our path to the root
-                       XmlNode curParent = _parent;
-                       while ( (curParent != null) & (! ownerDocument.Equals(curParent) ))
-                       {
-                               if (curParent.Equals(newChild) )
-                                       throw new ArgumentException("Cannot insert ancestor a node");
-                               curParent = curParent.ParentNode;
-                       }
+
+               [MonoTODO]
+               public virtual XmlNode RemoveChild (XmlNode oldChild)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNode ReplaceChild (XmlNode newChild, XmlNode oldChild)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNodeList SelectNodes (string xpath)
+               {
+                       throw new NotImplementedException ();
                }
 
-               // Constructors
-               //===========================================================================
-               //When we're first created, we won't know parent, etc.
-               internal XmlNode( XmlDocument aOwnerDoc )
+               [MonoTODO]
+               public virtual XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr)
                {
-                       // Don't create childnodes object, since not all derived classes have children
-                       FOwnerDocument = aOwnerDoc;
+                       throw new NotImplementedException ();
                }
 
-       }       // XmlNode
-}      // using namespace System.Xml
+               [MonoTODO]
+               public virtual XmlNode SelectSingleNode (string xpath)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public virtual XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               internal void SetParentNode (XmlNode parent)
+               {
+                       parentNode = parent;
+               }
+
+               [MonoTODO]
+               public virtual bool Supports (string feature, string version)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               public abstract void WriteContentTo (XmlWriter w);
+
+               [MonoTODO]
+               public abstract void WriteTo (XmlWriter w);
 
-               
+               #endregion
+       }
+}
index c186df48c3741bd5a23d5ace85e5b0d664d2f2dc..582ac99654eae4a079b03c4726beb53864aa982e 100644 (file)
@@ -80,7 +80,7 @@ namespace System.Xml
 
                public override XmlNode CloneNode(bool deep)
                {
-                       return new XmlProcessingInstruction(target, data, FOwnerDocument);
+                       return new XmlProcessingInstruction(target, data, OwnerDocument);
                }
 
                [MonoTODO]
index 0812a35431750fccfcab2d62e433d30b179f8166..04ee8ab7fcd420b5b4ab1e2b8032ae129e9c9762 100644 (file)
@@ -1,3 +1,10 @@
+2002-03-06  Kral Ferch <kral_ferch@hotmail.com>
+
+       * XmlAttributeTests.cs: Fixed bug in TestHasChildNodes test.
+       
+       * XmlDocumentTests.cs: Started work on some tests for invalid data in
+       various nodes created by the document.
+
 2002-03-02  Kral Ferch <kral_ferch@hotmail.com>
 
        * XmlDocumentTests.cs: New tests TestLoadProcessingInstruction(),
index baaa437b90520139faa1f4d796b879e4a358a779..5e8e50353933c7427ffe6ab5202b37d391ad27b3 100644 (file)
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "ChangeLog"
+                    BuildAction = "None"
+                />
                 <File
                     RelPath = "NameTableTests.cs"
                     SubType = "Code"
index 5299c1ee43e9ae53e318e2f89b96e2de2bc1b5e0..22c55508c8389367fa981e09d6f40e6c3f97205f 100644 (file)
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "ChangeLog"
+                    BuildAction = "None"
+                />
                 <File
                     RelPath = "NameTableTests.cs"
                     SubType = "Code"
index 6ee4911a2112d96415d52aed218b04e62d33cda8..54e73253ea350bdbca951fbea5ce3b56a5fc9173 100644 (file)
@@ -33,7 +33,7 @@ namespace Ximian.Mono.Tests
 
                public void TestHasChildNodes()
                {
-                       Assert("Child nodes not allowed", attr.HasChildNodes);
+                       Assert("Child nodes not allowed", attr.HasChildNodes == false);
                }
 
                public void TestName()
index 82dba031c93a3cc1812d0ec1cfc1310e3813c3ac..9850ce434172114b8c1843c5c1c082912f576bcb 100644 (file)
@@ -17,6 +17,62 @@ namespace Ximian.Mono.Tests
                        document = new XmlDocument ();
                }
 
+               ///////////////////////////////////////////////////////////////////////
+               //
+               //  Createxxx() tests.
+               //
+               ///////////////////////////////////////////////////////////////////////
+               
+               public void TestCreateProcessingInstructionInvalid()
+               {
+                       XmlProcessingInstruction processingInstruction;
+//                     string outerXml;
+
+                       // A newly created node should/shouldn't? have a parent or a documentelement?
+                       // need to make a test to find out.
+
+
+                       // Invalid contents doesn't fail on the create but will on methods
+                       // like OuterXml.
+
+//                     processingInstruction = null;
+//                     processingInstruction = document.CreateProcessingInstruction("foo", "bar?>baz");
+//                     Assert(processingInstruction != null);
+//                     document.AppendChild(processingInstruction);
+//                     try {
+//                             outerXml = document.OuterXml;
+//                             Fail("Should have thrown an ArgumentException.");
+//                     } catch (ArgumentException) { }
+                       
+
+                       processingInstruction = null;
+                       processingInstruction = document.CreateProcessingInstruction("foo", "bar?>baz");
+                       Assert(processingInstruction != null);
+                       
+                       processingInstruction = null;
+                       processingInstruction = document.CreateProcessingInstruction("XML", "bar");
+                       Assert(processingInstruction != null);
+                       
+                       processingInstruction = null;
+                       processingInstruction = document.CreateProcessingInstruction("xml", "bar");
+                       Assert(processingInstruction != null);
+
+                       try {
+                               Fail("Should have thrown an Exception.");
+                       }
+                       catch (Exception e) {
+                               string billy = e.Message;
+                       }
+
+               }
+
+
+               ///////////////////////////////////////////////////////////////////////
+               //
+               //  LoadXml(string) tests.
+               //
+               ///////////////////////////////////////////////////////////////////////
+
                public void TestLoadProcessingInstruction ()
                {
                        document.LoadXml (@"<?foo bar='baaz' quux='quuux'?><quuuux></quuuux>");
@@ -26,15 +82,15 @@ namespace Ximian.Mono.Tests
                public void TestLoadCDATA ()
                {
                        document.LoadXml ("<foo><![CDATA[bar]]></foo>");
-                       Assert (document.DocumentElement.ChildNodes [0].NodeType == XmlNodeType.CDATA);
-                       AssertEquals ("bar", document.DocumentElement.ChildNodes [0].Value);
+                       Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.CDATA);
+                       AssertEquals ("bar", document.DocumentElement.FirstChild.Value);
                }
 
                public void TestLoadComment()
                {
                        document.LoadXml ("<foo><!--Comment--></foo>");
-                       Assert (document.DocumentElement.ChildNodes [0].NodeType == XmlNodeType.Comment);
-                       AssertEquals ("Comment", document.DocumentElement.ChildNodes [0].Value);
+                       Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.Comment);
+                       AssertEquals ("Comment", document.DocumentElement.FirstChild.Value);
                }
 
                public void TestLoadXmlSingleElement ()
@@ -44,36 +100,36 @@ namespace Ximian.Mono.Tests
                        AssertNotNull (document.DocumentElement);
 
                        AssertSame (document.FirstChild, document.DocumentElement);
-                       AssertSame (document.ChildNodes [0], document.DocumentElement);
+                       AssertSame (document.FirstChild, document.DocumentElement);
                }
 
                public void TestLoadXmlExceptionClearsDocument ()
                {
                        document.LoadXml ("<foo/>");
-                       Assert (document.ChildNodes.Count > 0);
+                       Assert (document.FirstChild != null);
                        
                        try {
                                document.LoadXml ("<123/>");
                                Fail ("An XmlException should have been thrown.");
                        } catch (XmlException) {}
 
-                       Assert (document.ChildNodes.Count == 0);
+                       Assert (document.FirstChild == null);
                }
 
                public void TestLoadXmlElementWithChildElement ()
                {
                        document.LoadXml ("<foo><bar/></foo>");
-                       Assert (document.ChildNodes.Count == 1);
-                       Assert (document.ChildNodes [0].ChildNodes.Count == 1);
+//                     Assert (document.ChildNodes.Count == 1);
+//                     Assert (document.FirstChild.ChildNodes.Count == 1);
                        AssertEquals ("foo", document.DocumentElement.LocalName);
-                       AssertEquals ("bar", document.DocumentElement.ChildNodes [0].LocalName);
+                       AssertEquals ("bar", document.DocumentElement.FirstChild.LocalName);
                }
 
                public void TestLoadXmlElementWithTextNode ()
                {
                        document.LoadXml ("<foo>bar</foo>");
-                       Assert (document.DocumentElement.ChildNodes [0].NodeType == XmlNodeType.Text);
-                       AssertEquals ("bar", document.DocumentElement.ChildNodes [0].Value);
+                       Assert (document.DocumentElement.FirstChild.NodeType == XmlNodeType.Text);
+                       AssertEquals ("bar", document.DocumentElement.FirstChild.Value);
                }
 
                public void TestDocumentElement ()