diff options
author | Kral Ferch <kral@mono-cvs.ximian.com> | 2002-03-08 07:45:30 +0300 |
---|---|---|
committer | Kral Ferch <kral@mono-cvs.ximian.com> | 2002-03-08 07:45:30 +0300 |
commit | 80544603320ecb07162901d05cd43dc57db4634a (patch) | |
tree | 8de47ad96bd47b2a552b383de8d72c741b335b9b /mcs | |
parent | a6954ab4d428f74c8c8d447acaf06cf0f26c48f2 (diff) |
XmlNodeListChildren implements XmlNodeList for XmlNode.ChildNodes
svn path=/trunk/mcs/; revision=2987
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System.XML/Mono.System.XML.csproj | 2 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/ChangeLog | 15 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlDocument.cs | 26 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlElement.cs | 1 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlLinkedNode.cs | 20 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlNode.cs | 102 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlNodeList.cs | 73 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlNodeListAsArrayList.cs | 57 | ||||
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlNodeListChildren.cs | 154 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/AllTests.cs | 1 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/Microsoft.Test.csproj | 5 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/Mono.Test.csproj | 5 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/XmlNodeListTests.cs | 53 |
14 files changed, 381 insertions, 139 deletions
diff --git a/mcs/class/System.XML/Mono.System.XML.csproj b/mcs/class/System.XML/Mono.System.XML.csproj index b1e89e8a131..cfb344b6f04 100644 --- a/mcs/class/System.XML/Mono.System.XML.csproj +++ b/mcs/class/System.XML/Mono.System.XML.csproj @@ -266,7 +266,7 @@ BuildAction = "Compile" /> <File - RelPath = "System.Xml\XmlNodeListAsArrayList.cs" + RelPath = "System.Xml\XmlNodeListChildren.cs" SubType = "Code" BuildAction = "Compile" /> diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog index 038ccc6a7ed..8404c838592 100644 --- a/mcs/class/System.XML/System.Xml/ChangeLog +++ b/mcs/class/System.XML/System.Xml/ChangeLog @@ -1,3 +1,18 @@ +2002-03-08 Kral Ferch <kral_ferch@hotmail.com> + + * XmlNodeList.cs, XmlDocument.cs, XmlLinkedNode.cs, + XmlNode.cs: Formatting. + + * XmlNodeListChildren.cs: Implementation of XmlNodeList + for XmlNode.ChildNodes property. + + * XmlNodeListAsArrayList.cs: Removed file. Using different + data structure (circular list) in XmlNode so this file + is no longer valid. + + * XmlDocument.cs, XmlElement.cs: New ChildNodes tests found + bug in setter property of LastLinkedChild so fixed it. + 2002-03-06 Jason Diamond <jason@injektilo.org> * XmlInputSource.cs, XmlNames_1_0.cs, XmlParse.cs: Removed files. diff --git a/mcs/class/System.XML/System.Xml/XmlDocument.cs b/mcs/class/System.XML/System.Xml/XmlDocument.cs index 987112960e7..29dc09edad3 100644 --- a/mcs/class/System.XML/System.Xml/XmlDocument.cs +++ b/mcs/class/System.XML/System.Xml/XmlDocument.cs @@ -17,12 +17,22 @@ namespace System.Xml public class XmlDocument : XmlNode { #region Fields + /////////////////////////////////////////////////////////////////////// + // + // Fields + // + /////////////////////////////////////////////////////////////////////// private XmlLinkedNode lastChild; #endregion #region Constructors + /////////////////////////////////////////////////////////////////////// + // + // Constructors + // + /////////////////////////////////////////////////////////////////////// public XmlDocument () : base (null) { } @@ -41,6 +51,11 @@ namespace System.Xml #endregion #region Events + /////////////////////////////////////////////////////////////////////// + // + // Events + // + /////////////////////////////////////////////////////////////////////// public event XmlNodeChangedEventHandler NodeChanged; @@ -57,6 +72,11 @@ namespace System.Xml #endregion #region Properties + /////////////////////////////////////////////////////////////////////// + // + // Properties + // + /////////////////////////////////////////////////////////////////////// [MonoTODO] public override string BaseURI { @@ -124,6 +144,7 @@ namespace System.Xml value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling; LastLinkedChild.NextLinkedSibling = value; + lastChild = value; SetParentNode(this); } @@ -165,6 +186,11 @@ namespace System.Xml #endregion #region Methods + /////////////////////////////////////////////////////////////////////// + // + // Methods + // + /////////////////////////////////////////////////////////////////////// [MonoTODO] public override XmlNode CloneNode (bool deep) diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs index 857517c24f4..a86d86af1f3 100644 --- a/mcs/class/System.XML/System.Xml/XmlElement.cs +++ b/mcs/class/System.XML/System.Xml/XmlElement.cs @@ -115,6 +115,7 @@ namespace System.Xml value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling; LastLinkedChild.NextLinkedSibling = value; + lastChild = value; SetParentNode(this); } diff --git a/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs b/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs index e1675724e6c..2641eefeccf 100644 --- a/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs +++ b/mcs/class/System.XML/System.Xml/XmlLinkedNode.cs @@ -4,15 +4,34 @@ namespace System.Xml { public abstract class XmlLinkedNode : XmlNode { + #region Fields + /////////////////////////////////////////////////////////////////////// + // + // Fields + // + /////////////////////////////////////////////////////////////////////// + XmlLinkedNode nextSibling; + #endregion + #region Constructors + /////////////////////////////////////////////////////////////////////// + // + // Constructors + // + /////////////////////////////////////////////////////////////////////// protected internal XmlLinkedNode(XmlDocument doc) : base(doc) { } #endregion #region Properties + /////////////////////////////////////////////////////////////////////// + // + // Properties + // + /////////////////////////////////////////////////////////////////////// public override XmlNode NextSibling { @@ -41,6 +60,5 @@ namespace System.Xml } #endregion - } }
\ No newline at end of file diff --git a/mcs/class/System.XML/System.Xml/XmlNode.cs b/mcs/class/System.XML/System.Xml/XmlNode.cs index bfe9a942761..cac9cc9c9c5 100644 --- a/mcs/class/System.XML/System.Xml/XmlNode.cs +++ b/mcs/class/System.XML/System.Xml/XmlNode.cs @@ -1,5 +1,5 @@ // -// System.Xml.XmlProcessingInstruction +// System.Xml.XmlNode // // Author: // Kral Ferch <kral_ferch@hotmail.com> @@ -15,10 +15,24 @@ namespace System.Xml { public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable { + #region Fields + /////////////////////////////////////////////////////////////////////// + // + // Fields + // + /////////////////////////////////////////////////////////////////////// + XmlDocument ownerDocument; XmlNode parentNode; + #endregion + #region Constructors + /////////////////////////////////////////////////////////////////////// + // + // Constructors + // + /////////////////////////////////////////////////////////////////////// protected internal XmlNode(XmlDocument ownerDocument) { @@ -28,6 +42,11 @@ namespace System.Xml #endregion #region Properties + /////////////////////////////////////////////////////////////////////// + // + // Properties + // + /////////////////////////////////////////////////////////////////////// public virtual XmlAttributeCollection Attributes { @@ -40,14 +59,13 @@ namespace System.Xml get { throw new NotImplementedException (); } } - [MonoTODO] - public virtual XmlNodeList ChildNodes - { - get { throw new NotImplementedException (); } + public virtual XmlNodeList ChildNodes { + get { + return new XmlNodeListChildren(LastLinkedChild); + } } - public virtual XmlNode FirstChild - { + public virtual XmlNode FirstChild { get { if (LastChild != null) { return LastLinkedChild.NextLinkedSibling; @@ -58,114 +76,91 @@ namespace System.Xml } } - public virtual bool HasChildNodes - { + public virtual bool HasChildNodes { get { return LastChild != null; } } [MonoTODO] - public virtual string InnerText - { + public virtual string InnerText { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } [MonoTODO] - public virtual string InnerXml - { + public virtual string InnerXml { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } [MonoTODO] - public virtual bool IsReadOnly - { + public virtual bool IsReadOnly { get { throw new NotImplementedException (); } } [MonoTODO] - public virtual XmlElement this[string name] - { + [System.Runtime.CompilerServices.IndexerName("Item")] + public virtual XmlElement this [string name] { get { throw new NotImplementedException (); } } [MonoTODO] - public virtual XmlElement this[string localname, string ns] - { + [System.Runtime.CompilerServices.IndexerName("Item")] + public virtual XmlElement this [string localname, string ns] { get { throw new NotImplementedException (); } } - public virtual XmlNode LastChild - { + public virtual XmlNode LastChild { get { return LastLinkedChild; } } - internal virtual XmlLinkedNode LastLinkedChild - { + internal virtual XmlLinkedNode LastLinkedChild { get { return null; } set { } } [MonoTODO] - public abstract string LocalName - { - get; - } + public abstract string LocalName { get; } [MonoTODO] - public abstract string Name - { - get; - } + public abstract string Name { get; } [MonoTODO] - public virtual string NamespaceURI - { + public virtual string NamespaceURI { get { throw new NotImplementedException (); } } - public virtual XmlNode NextSibling - { + public virtual XmlNode NextSibling { get { return null; } } [MonoTODO] - public abstract XmlNodeType NodeType - { - get; - } + public abstract XmlNodeType NodeType { get; } [MonoTODO] - public virtual string OuterXml - { + public virtual string OuterXml { get { throw new NotImplementedException (); } } - public virtual XmlDocument OwnerDocument - { + public virtual XmlDocument OwnerDocument { get { return ownerDocument; } } - public virtual XmlNode ParentNode - { + public virtual XmlNode ParentNode { get { return parentNode; } } [MonoTODO] - public virtual string Prefix - { + public virtual string Prefix { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } - public virtual XmlNode PreviousSibling - { + public virtual XmlNode PreviousSibling { get { return null; } } [MonoTODO] - public virtual string Value - { + public virtual string Value { get { throw new NotImplementedException (); } set { throw new NotImplementedException (); } } @@ -173,6 +168,11 @@ namespace System.Xml #endregion #region Methods + /////////////////////////////////////////////////////////////////////// + // + // Methods + // + /////////////////////////////////////////////////////////////////////// public virtual XmlNode AppendChild (XmlNode newChild) { diff --git a/mcs/class/System.XML/System.Xml/XmlNodeList.cs b/mcs/class/System.XML/System.Xml/XmlNodeList.cs index 1d166b9f118..ef788fafb7c 100644 --- a/mcs/class/System.XML/System.Xml/XmlNodeList.cs +++ b/mcs/class/System.XML/System.Xml/XmlNodeList.cs @@ -1,42 +1,57 @@ +// +// System.Xml.XmlNodeList +// +// Author: +// Kral Ferch <kral_ferch@hotmail.com> +// +// (C) 2002 Kral Ferch +// + using System; using System.Collections; namespace System.Xml { - /// <summary> - /// Abstract class XmlNodeList. - /// </summary> public abstract class XmlNodeList : IEnumerable { - // public properties - public abstract int Count { get; } + #region Constructors + /////////////////////////////////////////////////////////////////////// + // + // Constructors + // + /////////////////////////////////////////////////////////////////////// + + protected internal XmlNodeList() { } + + #endregion + + #region Properties + /////////////////////////////////////////////////////////////////////// + // + // Properties + // + /////////////////////////////////////////////////////////////////////// + + public abstract int Count { get; } [System.Runtime.CompilerServices.IndexerName("ItemOf")] - public virtual XmlNode this[int i] - { - get - { - return Item(i); - } + public virtual XmlNode this [int i] { + get { return Item(i); } } - // Public Methods - /// <summary> - /// Abstract. Return the enumerator for the class. - /// </summary> - /// <returns>Enumerator</returns> - public abstract IEnumerator GetEnumerator(); - - /// <summary> - /// Abstract. Returns the item at index. Index is 0-based. - /// </summary> - /// <param name="index"></param> - /// <returns></returns> - public abstract XmlNode Item(int index); - - public XmlNodeList() - { - // TODO: What should be done in constructor for XmlNodeList.XmlNodeList()? (nothing) - } + #endregion + + #region Methods + /////////////////////////////////////////////////////////////////////// + // + // Methods + // + /////////////////////////////////////////////////////////////////////// + + public abstract IEnumerator GetEnumerator (); + + public abstract XmlNode Item (int index); + + #endregion } } diff --git a/mcs/class/System.XML/System.Xml/XmlNodeListAsArrayList.cs b/mcs/class/System.XML/System.Xml/XmlNodeListAsArrayList.cs deleted file mode 100644 index dccb526fc73..00000000000 --- a/mcs/class/System.XML/System.Xml/XmlNodeListAsArrayList.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections; - -namespace System.Xml -{ - /// <summary> - /// Internal implementation of XmlNodeList for XmlNode - /// </summary> - internal class XmlNodeListAsArrayList : XmlNodeList - { - // Private data members - ArrayList _items; - - // Public Methods - //=========================================================================== - public override int Count - { - get - { - return _items.Count; - } - } - - public IList data - { - get - { - return _items; - } - } - - // Public Methods - //=========================================================================== - public override IEnumerator GetEnumerator() - { - return _items.GetEnumerator(); - } - - public void Add(XmlNode node) - { - _items.Add(node); - } - - public override XmlNode Item(int index) - { - if ((index >= 0) & (index < _items.Count)) - return _items[index] as XmlNode; - else - return null; - } - - public XmlNodeListAsArrayList() : base() - { - _items = new ArrayList(); - } - } -} diff --git a/mcs/class/System.XML/System.Xml/XmlNodeListChildren.cs b/mcs/class/System.XML/System.Xml/XmlNodeListChildren.cs new file mode 100644 index 00000000000..dde6c4243ac --- /dev/null +++ b/mcs/class/System.XML/System.Xml/XmlNodeListChildren.cs @@ -0,0 +1,154 @@ +// +// System.Xml.XmlNodeList +// +// Author: +// Kral Ferch <kral_ferch@hotmail.com> +// +// (C) 2002 Kral Ferch +// + +using System; +using System.Collections; + +namespace System.Xml +{ + public class XmlNodeListChildren : XmlNodeList + { + #region Enumerator + /////////////////////////////////////////////////////////////////////// + // + // Enumerator + // + /////////////////////////////////////////////////////////////////////// + private class Enumerator : IEnumerator + { + XmlLinkedNode currentChild; + XmlLinkedNode lastChild; + + internal Enumerator (XmlLinkedNode lastChild) + { + currentChild = null; + this.lastChild = lastChild; + } + + public virtual object Current { + get { + return currentChild; + } + } + + public virtual bool MoveNext() + { + bool passedEndOfCollection = Object.ReferenceEquals(currentChild, lastChild); + + if (currentChild == null) { + currentChild = lastChild; + } + + currentChild = currentChild.NextLinkedSibling; + + return passedEndOfCollection; + } + + public virtual void Reset() + { + currentChild = null; + } + } + + #endregion + + #region Fields + /////////////////////////////////////////////////////////////////////// + // + // Fields + // + /////////////////////////////////////////////////////////////////////// + + XmlLinkedNode lastChild; + + #endregion + + #region Constructors + /////////////////////////////////////////////////////////////////////// + // + // Constructors + // + /////////////////////////////////////////////////////////////////////// + + public XmlNodeListChildren(XmlLinkedNode lastChild) + { + this.lastChild = lastChild; + } + + #endregion + + #region Properties + /////////////////////////////////////////////////////////////////////// + // + // Properties + // + /////////////////////////////////////////////////////////////////////// + + public override int Count { + get { + int count = 0; + + if (lastChild != null) { + XmlLinkedNode currentChild = lastChild.NextLinkedSibling; + + count = 1; + while (!Object.ReferenceEquals(currentChild, lastChild)) { + currentChild = currentChild.NextLinkedSibling; + count++; + } + } + + return count; + } + } + + #endregion + + #region Methods + /////////////////////////////////////////////////////////////////////// + // + // Methods + // + /////////////////////////////////////////////////////////////////////// + + public override IEnumerator GetEnumerator () + { + return new Enumerator(lastChild); + } + + public override XmlNode Item (int index) + { + XmlNode requestedNode = null; + + // Instead of checking for && index < Count which has to walk + // the whole list to get a count, we'll just keep a count since + // we have to walk the list anyways to get to index. + if ((index >= 0) && (lastChild != null)) { + XmlLinkedNode currentChild = lastChild.NextLinkedSibling; + int count = 0; + + while ((count < index) && !Object.ReferenceEquals(currentChild, lastChild)) + { + currentChild = currentChild.NextLinkedSibling; + count++; + } + + if (count == index) { + requestedNode = currentChild; + } + } + + return requestedNode; + } + + #endregion + } + + +} diff --git a/mcs/class/System.XML/Test/AllTests.cs b/mcs/class/System.XML/Test/AllTests.cs index cd3ccf5c8dd..9df4e5019bd 100644 --- a/mcs/class/System.XML/Test/AllTests.cs +++ b/mcs/class/System.XML/Test/AllTests.cs @@ -25,6 +25,7 @@ namespace Ximian.Mono.Tests suite.AddTest (new TestSuite (typeof (XmlDocumentTests))); suite.AddTest (new TestSuite (typeof (NameTableTests))); suite.AddTest (new TestSuite (typeof (XmlElementTests))); + suite.AddTest (new TestSuite (typeof (XmlNodeListTests))); return suite; } } diff --git a/mcs/class/System.XML/Test/ChangeLog b/mcs/class/System.XML/Test/ChangeLog index f71e2d88dfd..6934e040acf 100644 --- a/mcs/class/System.XML/Test/ChangeLog +++ b/mcs/class/System.XML/Test/ChangeLog @@ -1,3 +1,9 @@ +2002-03-08 Kral Ferch <kral_ferch@hotmail.com> + + * XmlNodeListTests.cs: New file. + + * AllTests.cs: Added XmlNodeListTests. + 2002/03/08 Nick Drochak <ndrochak@gol.com> * System_test.build: Don't build test dll by default. Only build diff --git a/mcs/class/System.XML/Test/Microsoft.Test.csproj b/mcs/class/System.XML/Test/Microsoft.Test.csproj index 5e8e5035393..d573a5eb428 100644 --- a/mcs/class/System.XML/Test/Microsoft.Test.csproj +++ b/mcs/class/System.XML/Test/Microsoft.Test.csproj @@ -111,6 +111,11 @@ BuildAction = "Compile" /> <File + RelPath = "XmlNodeListTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "XmlTextReaderTests.cs" SubType = "Code" BuildAction = "Compile" diff --git a/mcs/class/System.XML/Test/Mono.Test.csproj b/mcs/class/System.XML/Test/Mono.Test.csproj index 22c55508c83..2b0d0a4822f 100644 --- a/mcs/class/System.XML/Test/Mono.Test.csproj +++ b/mcs/class/System.XML/Test/Mono.Test.csproj @@ -116,6 +116,11 @@ BuildAction = "Compile" /> <File + RelPath = "XmlNodeListTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "XmlTextReaderTests.cs" SubType = "Code" BuildAction = "Compile" diff --git a/mcs/class/System.XML/Test/XmlNodeListTests.cs b/mcs/class/System.XML/Test/XmlNodeListTests.cs new file mode 100644 index 00000000000..b786b8ade6d --- /dev/null +++ b/mcs/class/System.XML/Test/XmlNodeListTests.cs @@ -0,0 +1,53 @@ +using System; +using System.Xml; + +using NUnit.Framework; + +namespace Ximian.Mono.Tests +{ + public class XmlNodeListTests : TestCase + { + public XmlNodeListTests () : base ("Ximian.Mono.Tests.XmlNodeListTests testsuite") {} + public XmlNodeListTests (string name) : base (name) {} + + private XmlElement element; + + protected override void SetUp () + { + XmlDocument document = new XmlDocument (); + + document.LoadXml ("<foo><child1/><child2/><child3/></foo>"); + element = document.DocumentElement; + } + + /////////////////////////////////////////////////////////////////////// + // + // XmlNodeListChildren tests. + // + /////////////////////////////////////////////////////////////////////// + + public void TestChildren() + { + Assert ("Incorrect number of children returned from Count property.", element.ChildNodes.Count == 3); + AssertNull ("Index less than zero should have returned null.", element.ChildNodes [-1]); + AssertNull ("Index greater than or equal to Count should have returned null.", element.ChildNodes [3]); + AssertEquals ("Didn't return the correct child.", element.FirstChild, element.ChildNodes[0]); + AssertEquals ("Didn't return the correct child.", "child1", element.ChildNodes[0].LocalName); + AssertEquals ("Didn't return the correct child.", "child2", element.ChildNodes[1].LocalName); + AssertEquals ("Didn't return the correct child.", "child3", element.ChildNodes[2].LocalName); + + int index = 1; + foreach (XmlNode node in element.ChildNodes) { + AssertEquals ("Enumerator didn't return correct node.", "child" + index.ToString(), node.LocalName); + index++; + } + } + + + /////////////////////////////////////////////////////////////////////// + // + // XmlNodeListSelect tests. + // + /////////////////////////////////////////////////////////////////////// + } +} |