BuildAction = "Compile"
/>
<File
- RelPath = "System.Xml\XmlNodeListAsArrayList.cs"
+ RelPath = "System.Xml\XmlNodeListChildren.cs"
SubType = "Code"
BuildAction = "Compile"
/>
+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.
public class XmlDocument : XmlNode
{
#region Fields
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Fields
+ //
+ ///////////////////////////////////////////////////////////////////////
private XmlLinkedNode lastChild;
#endregion
#region Constructors
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Constructors
+ //
+ ///////////////////////////////////////////////////////////////////////
public XmlDocument () : base (null) { }
#endregion
#region Events
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Events
+ //
+ ///////////////////////////////////////////////////////////////////////
public event XmlNodeChangedEventHandler NodeChanged;
#endregion
#region Properties
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Properties
+ //
+ ///////////////////////////////////////////////////////////////////////
[MonoTODO]
public override string BaseURI {
value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling;
LastLinkedChild.NextLinkedSibling = value;
+ lastChild = value;
SetParentNode(this);
}
#endregion
#region Methods
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Methods
+ //
+ ///////////////////////////////////////////////////////////////////////
[MonoTODO]
public override XmlNode CloneNode (bool deep)
value.NextLinkedSibling = LastLinkedChild.NextLinkedSibling;
LastLinkedChild.NextLinkedSibling = value;
+ lastChild = value;
SetParentNode(this);
}
{
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
{
}
#endregion
-
}
}
\ No newline at end of file
//
-// System.Xml.XmlProcessingInstruction
+// System.Xml.XmlNode
//
// Author:
// Kral Ferch <kral_ferch@hotmail.com>
{
public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
{
+ #region Fields
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Fields
+ //
+ ///////////////////////////////////////////////////////////////////////
+
XmlDocument ownerDocument;
XmlNode parentNode;
+ #endregion
+
#region Constructors
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Constructors
+ //
+ ///////////////////////////////////////////////////////////////////////
protected internal XmlNode(XmlDocument ownerDocument)
{
#endregion
#region Properties
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Properties
+ //
+ ///////////////////////////////////////////////////////////////////////
public virtual XmlAttributeCollection Attributes
{
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;
}
}
- 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 (); }
}
#endregion
#region Methods
+ ///////////////////////////////////////////////////////////////////////
+ //
+ // Methods
+ //
+ ///////////////////////////////////////////////////////////////////////
public virtual XmlNode AppendChild (XmlNode newChild)
{
+//
+// 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
}
}
+++ /dev/null
-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();
- }
- }
-}
--- /dev/null
+//
+// 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
+ }
+
+
+}
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;
}
}
+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
SubType = "Code"
BuildAction = "Compile"
/>
+ <File
+ RelPath = "XmlNodeListTests.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
<File
RelPath = "XmlTextReaderTests.cs"
SubType = "Code"
SubType = "Code"
BuildAction = "Compile"
/>
+ <File
+ RelPath = "XmlNodeListTests.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
<File
RelPath = "XmlTextReaderTests.cs"
SubType = "Code"
--- /dev/null
+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.
+ //
+ ///////////////////////////////////////////////////////////////////////
+ }
+}