dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml ElementList.cs,1.1,1.2 Xml


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml ElementList.cs,1.1,1.2 XmlElement.cs,1.6,1.7 XmlTextWriter.cs,1.7,1.8
Date: Thu, 12 Dec 2002 22:45:09 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv6611/System.Xml

Modified Files:
        ElementList.cs XmlElement.cs XmlTextWriter.cs 
Log Message:


New test cases for "XmlElement".


Index: ElementList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/ElementList.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ElementList.cs      9 Dec 2002 04:04:04 -0000       1.1
--- ElementList.cs      13 Dec 2002 03:45:07 -0000      1.2
***************
*** 28,61 ****
  {
        // Internal state.
!       private XmlElement element;
        private String name;
        private String namespaceURI;
        private bool uriForm;
  
        // Create a new element list.
!       public ElementList(XmlElement element, String name)
                        {
!                               this.element = element;
!                               this.name = name;
                                this.namespaceURI = null;
                                this.uriForm = false;
                        }
!       public ElementList(XmlElement element, String localName,
                                           String namespaceURI)
                        {
!                               this.element = element;
!                               this.name = localName;
!                               this.namespaceURI = namespaceURI;
                                this.uriForm = true;
                        }
  
        // Get the number of entries in the node list.
-       [TODO]
        public override int Count
                        {
                                get
                                {
!                                       // TODO
!                                       return 0;
                                }
                        }
--- 28,156 ----
  {
        // 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)
!                       {
!                               this.name = doc.NameTable.Add(name);
                                this.namespaceURI = null;
                                this.uriForm = false;
                        }
!       public ElementList(XmlNode parent, String localName,
                                           String namespaceURI)
+                       : this(parent)
                        {
!                               this.name =
!                                       (localName != null ? 
doc.NameTable.Add(localName) : null);
!                               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;
                                }
                        }

Index: XmlElement.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlElement.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** XmlElement.cs       9 Dec 2002 04:04:04 -0000       1.6
--- XmlElement.cs       13 Dec 2002 03:45:07 -0000      1.7
***************
*** 87,91 ****
                                        {
                                                // Remove the children and 
create a new text node.
!                                               RemoveAll();
                                                
AppendChild(OwnerDocument.CreateTextNode(value));
                                        }
--- 87,91 ----
                                        {
                                                // Remove the children and 
create a new text node.
!                                               RemoveContents();
                                                
AppendChild(OwnerDocument.CreateTextNode(value));
                                        }
***************
*** 107,111 ****
                        }
  
!       // Get or set the format of this element.
        public bool IsEmpty
                        {
--- 107,111 ----
                        }
  
!       // Get or set the empty state of this element.
        public bool IsEmpty
                        {
***************
*** 116,119 ****
--- 116,123 ----
                                set
                                {
+                                       if(value)
+                                       {
+                                               RemoveContents();
+                                       }
                                        isEmpty = value;
                                }
***************
*** 197,201 ****
                                XmlElement clone = OwnerDocument.CreateElement
                                        (Prefix, LocalName, NamespaceURI);
-                               clone.isEmpty = isEmpty;
                                if(attributes != null)
                                {
--- 201,204 ----
***************
*** 309,312 ****
--- 312,321 ----
                        }
  
+       // Remove the element contents, but not the attributes.
+       private void RemoveContents()
+                       {
+                               base.RemoveAll();
+                       }
+ 
        // Remove a specified attribute by name.
        public virtual void RemoveAttribute(String name)
***************
*** 447,451 ****
                                        }
                                }
!                               if(!isEmpty)
                                {
                                        WriteContentTo(w);
--- 456,460 ----
                                        }
                                }
!                               if(!IsEmpty)
                                {
                                        WriteContentTo(w);

Index: XmlTextWriter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextWriter.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** XmlTextWriter.cs    9 Dec 2002 04:52:56 -0000       1.7
--- XmlTextWriter.cs    13 Dec 2002 03:45:07 -0000      1.8
***************
*** 696,703 ****
                                // Pop the current scope.
                                PopScope();
-                               if(xmlSpace != System.Xml.XmlSpace.Preserve)
-                               {
-                                       writer.WriteLine();
-                               }
                                writeState = System.Xml.WriteState.Content;
                                prevWasText = false;
--- 696,699 ----
***************
*** 751,758 ****
                                // Pop the current scope.
                                PopScope();
-                               if(xmlSpace != System.Xml.XmlSpace.Preserve)
-                               {
-                                       writer.WriteLine();
-                               }
                                writeState = System.Xml.WriteState.Content;
                                prevWasText = false;
--- 747,750 ----
***************
*** 999,1003 ****
                                }
                                writer.Write('<');
!                               if(((Object)prefix) != null && ((Object)ns) != 
null)
                                {
                                        // We need to associate a prefix with a 
namespace.
--- 991,996 ----
                                }
                                writer.Write('<');
!                               if(((Object)prefix) != null && prefix != 
String.Empty &&
!                                  ((Object)ns) != null && ns != String.Empty)
                                {
                                        // We need to associate a prefix with a 
namespace.
***************
*** 1031,1035 ****
                                        }
                                }
!                               else if(((Object)prefix) != null)
                                {
                                        // We were only given a prefix, so 
output it directly.
--- 1024,1028 ----
                                        }
                                }
!                               else if(((Object)prefix) != null && prefix != 
String.Empty)
                                {
                                        // We were only given a prefix, so 
output it directly.
***************
*** 1042,1046 ****
                                        writer.Write(localName);
                                }
!                               else if(((Object)ns) != null)
                                {
                                        // We were only given a namespace, so 
find the prefix.
--- 1035,1039 ----
                                        writer.Write(localName);
                                }
!                               else if(((Object)ns) != null && ns != 
String.Empty)
                                {
                                        // We were only given a namespace, so 
find the prefix.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]