[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml ElementList.cs,1.2,1.3
From: |
Adam Ballai <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml ElementList.cs,1.2,1.3 |
Date: |
Sun, 27 Apr 2003 08:34:03 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv28539/System.Xml
Modified Files:
ElementList.cs
Log Message:
Finish TODOs in ElementList
Index: ElementList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/ElementList.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ElementList.cs 13 Dec 2002 03:45:07 -0000 1.2
--- ElementList.cs 27 Apr 2003 12:34:01 -0000 1.3
***************
*** 22,56 ****
{
! using System;
! using System.Collections;
! internal class ElementList : XmlNodeList
! {
! // Internal state.
! private XmlNode parent;
! private XmlDocument doc;
! private String name;
! private String namespaceURI;
! private String matchAll;
! private bool uriForm;
! private bool docChanged;
! private XmlNode lastItem;
! private int lastItemAt;
!
! // Create a new element list.
! private ElementList(XmlNode parent)
! {
! this.parent = parent;
! this.doc = parent.OwnerDocument;
! this.matchAll = doc.NameTable.Add("*");
! this.docChanged = false;
! this.lastItem = null;
! this.lastItemAt = -1;
! this.doc.NodeInserted +=
! new
XmlNodeChangedEventHandler(DocumentChanged);
! this.doc.NodeRemoved +=
! new
XmlNodeChangedEventHandler(DocumentChanged);
! }
! public ElementList(XmlNode parent, String name)
: this(parent)
{
--- 22,56 ----
{
! using System;
! using System.Collections;
! internal class ElementList : XmlNodeList
! {
! // Internal state.
! private XmlNode parent;
! private XmlDocument doc;
! private String name;
! private String namespaceURI;
! private String matchAll;
! private bool uriForm;
! private bool docChanged;
! private XmlNode lastItem;
! private int lastItemAt;
!
! // Create a new element list.
! private ElementList(XmlNode parent)
! {
! this.parent = parent;
! this.doc = parent.OwnerDocument;
! this.matchAll = doc.NameTable.Add("*");
! this.docChanged = false;
! this.lastItem = null;
! this.lastItemAt = -1;
! this.doc.NodeInserted +=
! new XmlNodeChangedEventHandler(DocumentChanged);
! this.doc.NodeRemoved +=
! new XmlNodeChangedEventHandler(DocumentChanged);
! }
! public ElementList(XmlNode parent, String name)
: this(parent)
{
***************
*** 59,64 ****
this.uriForm = false;
}
! public ElementList(XmlNode parent, String localName,
! String namespaceURI)
: this(parent)
{
--- 59,64 ----
this.uriForm = false;
}
! public ElementList(XmlNode parent, String localName,
! String namespaceURI)
: this(parent)
{
***************
*** 67,176 ****
this.namespaceURI =
(namespaceURI != null
! ?
doc.NameTable.Add(namespaceURI) : null);
this.uriForm = true;
}
! // Track changes to the document that may affect the search order.
! private void DocumentChanged(Object sender, XmlNodeChangedEventArgs
args)
{
! docChanged = true;
}
! // Get the node that follows another in pre-order traversal.
! private XmlNode GetFollowingNode(XmlNode node)
{
! XmlNode current = node.FirstChild;
! if(current == null)
{
! // We don't have any children, so look
for a next sibling.
! current = node;
! while(current != null && current !=
parent &&
! current.NextSibling == null)
! {
! current = current.ParentNode;
! }
! if(current != null && current != parent)
{
! current = current.NextSibling;
}
}
! if(current == parent)
{
! // We've finished the traversal.
! return null;
}
! else
{
! // This is the next node in sequence.
! return current;
}
}
! // Determine if a node matches the selection criteria.
! private bool NodeMatches(XmlNode node)
{
! if(node.NodeType != XmlNodeType.Element)
{
! return false;
}
! if(!uriForm)
{
! if(((Object)name) == ((Object)matchAll)
||
! ((Object)name) ==
((Object)(node.Name)))
{
return true;
}
}
else
{
! if(((Object)name) == ((Object)matchAll)
||
! ((Object)name) ==
((Object)(node.LocalName)))
! {
! if(((Object)namespaceURI) ==
((Object)matchAll) ||
! ((Object)namespaceURI) ==
!
((Object)(node.NamespaceURI)))
! {
! return true;
! }
! }
}
- return false;
}
!
! // Get the number of entries in the node list.
! public override int Count
{
get
{
! int count = 0;
! XmlNode current = parent;
! while((current =
GetFollowingNode(current)) != null)
{
! if(NodeMatches(current))
! {
! ++count;
! }
}
- return count;
}
}
! // Get a particular item within this node list.
! [TODO]
! public override XmlNode Item(int i)
! {
! // TODO
! return null;
! }
!
! // Implement the "IEnumerable" interface.
! [TODO]
! public override IEnumerator GetEnumerator()
! {
! // TODO
! return null;
! }
! }; // class ElementList
}; // namespace System.Xml
--- 67,285 ----
this.namespaceURI =
(namespaceURI != null
! ? doc.NameTable.Add(namespaceURI) :
null);
this.uriForm = true;
}
! // Track changes to the document that may affect the search
order.
! private void DocumentChanged(Object sender,
XmlNodeChangedEventArgs args)
! {
! docChanged = true;
! }
!
! // Get the node that follows another in pre-order traversal.
! private XmlNode GetFollowingNode(XmlNode node)
! {
! XmlNode current = node.FirstChild;
! if(current == null)
! {
! // We don't have any children, so look for a
next sibling.
! current = node;
! while(current != null && current != parent &&
! current.NextSibling == null)
! {
! current = current.ParentNode;
! }
! if(current != null && current != parent)
! {
! current = current.NextSibling;
! }
! }
! if(current == parent)
{
! // We've finished the traversal.
! return null;
! }
! else
! {
! // This is the next node in sequence.
! return current;
}
+ }
! // Determine if a node matches the selection criteria.
! private bool NodeMatches(XmlNode node)
! {
! if(node.NodeType != XmlNodeType.Element)
{
! return false;
! }
! if(!uriForm)
! {
! if(((Object)name) == ((Object)matchAll) ||
! ((Object)name) ==
((Object)(node.Name)))
{
! return true;
! }
! }
! else
! {
! if(((Object)name) == ((Object)matchAll) ||
! ((Object)name) ==
((Object)(node.LocalName)))
! {
! if(((Object)namespaceURI) ==
((Object)matchAll) ||
! ((Object)namespaceURI)
==
!
((Object)(node.NamespaceURI)))
{
! return true;
}
}
! }
! return false;
! }
!
! // Get the number of entries in the node list.
! public override int Count
! {
! get
! {
! int count = 0;
! XmlNode current = parent;
! while((current = GetFollowingNode(current)) !=
null)
{
! if(NodeMatches(current))
! {
! ++count;
! }
}
! return count;
! }
! }
!
! // Get a particular item within this node list.
! public override XmlNode Item(int i)
! {
! if(i >= this.Count)
! {
! return null;
! }
! XmlNode item = parent;
! int a = -1;
! while((item = GetFollowingNode(item)) != null)
! {
!
! if(NodeMatches(item))
{
! a++;
! if(i == a) return item;
}
+
+
+ }
+ return null;
+ }
+
+ // Implement the "IEnumerable" interface.
+ public override IEnumerator GetEnumerator()
+ {
+ return new NodeListEnumerator(this);
+ }
+
+ // Tell if document has been modified
+ internal bool IsModified
+ {
+ get
+ {
+ return docChanged;
}
+ }
+
+ // Implementation of the node list enumerator.
+ private sealed class NodeListEnumerator : IEnumerator
+ {
+ // Internal state.
+ private ElementList list;
+ private XmlNode current;
+ private bool isModified;
+ private bool done;
! // Constructor.
! public NodeListEnumerator(ElementList list)
{
! this.list = list;
! this.current = null;
! this.isModified = false;
! this.done = false;
! }
!
! // Implement the "IEnumerator" interface.
! public bool MoveNext()
! {
! if(isModified != list.IsModified)
{
! throw new InvalidOperationException
!
(S._("Invalid_CollectionModified"));
}
! if(current == null)
{
! if(done)
! {
! return false;
! }
! current = list.parent;
! if(current == null)
! {
! done = true;
! return false;
! }
! else
{
return true;
}
}
+ current = current.list.nextSibling;
+ if(current != null)
+ {
+ return true;
+ }
else
{
! done = true;
! return false;
}
}
! public void Reset()
! {
! if(isModified != list.IsModified)
! {
! throw new InvalidOperationException
!
(S._("Invalid_CollectionModified"));
! }
! current = null;
! done = false;
! }
! public Object Current
{
get
{
! if(isModified != list.IsModified)
! {
! throw new
InvalidOperationException
!
(S._("Invalid_CollectionModified"));
! }
! if(current != null)
{
! return current;
! }
! else
! {
! throw new
InvalidOperationException
!
(S._("Invalid_BadEnumeratorPosition"));
}
}
}
! }; // class NodeListEnumerator
! }; // class ElementList
}; // namespace System.Xml
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml ElementList.cs,1.2,1.3,
Adam Ballai <address@hidden> <=