2003-06-01 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Sun, 1 Jun 2003 05:56:49 +0000 (05:56 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sun, 1 Jun 2003 05:56:49 +0000 (05:56 -0000)
* XmlDocumentNavigator.cs : Compute document node one time.
  MoveToFirstChild() should move to PIs and comments.

svn path=/trunk/mcs/; revision=15039

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs

index ec88bfeae804339842aec57dee88f46daaaa37d2..57e3544488f73ad7fd55b0b8a16bec5d57991f5d 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-01  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * XmlDocumentNavigator.cs : Compute document node one time.
+         MoveToFirstChild() should move to PIs and comments.
+
 2003-05-30  Miguel de Icaza  <miguel@ximian.com>
 
        * XmlReader.cs (ReadStartElement): Improve error message.  
index 1dfd0491acf195066f0214fdb00de61e99ef5599..c22d8d910d283f2a8181bedc308d30dd49dad3d3 100644 (file)
@@ -18,10 +18,11 @@ namespace System.Xml
        {\r
                #region Constructors\r
 \r
-               [MonoTODO]
                internal XmlDocumentNavigator(XmlNode node)\r
                {\r
                        this.node = node;\r
+                       this.document = node.NodeType == XmlNodeType.Document ?\r
+                               node as XmlDocument : node.OwnerDocument;\r
                }\r
 \r
                #endregion\r
@@ -29,6 +30,7 @@ namespace System.Xml
                #region Fields\r
 \r
                private XmlNode node;\r
+               private XmlDocument document;\r
                private IEnumerator attributesEnumerator;\r
 \r
                #endregion\r
@@ -97,7 +99,7 @@ namespace System.Xml
 
                public override XmlNameTable NameTable {
                        get {
-                               return node.OwnerDocument.NameTable;
+                               return document.NameTable;
                        }
                }
 
@@ -173,7 +175,7 @@ namespace System.Xml
                {
                        XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
                        if (otherDocumentNavigator != null) {
-                               if (node.OwnerDocument == otherDocumentNavigator.node.OwnerDocument) {
+                               if (document == otherDocumentNavigator.document) {
                                        node = otherDocumentNavigator.node;
                                        return true;
                                }
@@ -215,9 +217,27 @@ namespace System.Xml
                public override bool MoveToFirstChild ()
                {
                        if (HasChildren) {
-                               node = (NodeType == XPathNodeType.Root) ?
-                                       ((XmlDocument) node).DocumentElement :
-                                       node.FirstChild;
+                               if (node == document) {
+                                       XmlNode n = node.FirstChild;
+                                       if (n == null)
+                                               return false;
+                                       bool loop = true;
+                                       do {
+                                               switch (node.NodeType) {
+                                               case XmlNodeType.XmlDeclaration:
+                                               case XmlNodeType.DocumentType:
+                                                       n = node.NextSibling;
+                                                       if (n == null)
+                                                               return false;
+                                                       break;
+                                               default:
+                                                       loop = false;
+                                                       break;
+                                               }
+                                       } while (loop);
+                               }
+                               else
+                                       node = node.FirstChild;
                                return true;
                        }
                        return false;
@@ -231,14 +251,7 @@ namespace System.Xml
 
                public override bool MoveToId (string id)
                {
-                       XmlDocument doc;
-                       
-                       if (node.NodeType == XmlNodeType.Document)
-                               doc = (XmlDocument) node;
-                       else
-                               doc = node.OwnerDocument;
-
-                       XmlElement eltNew = doc.GetElementById (id);
+                       XmlElement eltNew = document.GetElementById (id);
                        if (eltNew == null)
                                return false;
 
@@ -302,8 +315,7 @@ namespace System.Xml
 
                public override void MoveToRoot ()
                {
-                       if (node.NodeType != XmlNodeType.Document)
-                               node = node.OwnerDocument;
+                       node = document;
                }
 
                internal XmlNode Node { get { return node; } }