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 XmlFragmentTextWriter.cs,N


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlFragmentTextWriter.cs,NONE,1.1 XmlSpecialAttribute.cs,NONE,1.1 NodeList.cs,1.3,1.4 XmlAttribute.cs,1.3,1.4 XmlAttributeCollection.cs,1.3,1.4 XmlDeclaration.cs,1.1,1.2 XmlDocument.cs,1.4,1.5 XmlDocumentFragment.cs,1.1,1.2 XmlDocumentType.cs,1.2,1.3 XmlElement.cs,1.3,1.4 XmlEntityReference.cs,1.1,1.2 XmlNode.cs,1.9,1.10 XmlTextReader.cs,1.8,1.9
Date: Thu, 05 Dec 2002 17:19:55 -0500

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

Modified Files:
        NodeList.cs XmlAttribute.cs XmlAttributeCollection.cs 
        XmlDeclaration.cs XmlDocument.cs XmlDocumentFragment.cs 
        XmlDocumentType.cs XmlElement.cs XmlEntityReference.cs 
        XmlNode.cs XmlTextReader.cs 
Added Files:
        XmlFragmentTextWriter.cs XmlSpecialAttribute.cs 
Log Message:


Continue implementing the "System.Xml" namespace.


--- NEW FILE ---
/*
 * XmlFragmentTextWriter.cs - Implementation of the
 *              "System.Xml.XmlFragmentTextWriter" class.
 *
 * Copyright (C) 2002 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
namespace System.Xml
{

using System;
using System.IO;
using System.Text;
using System.Globalization;

// This class is used for outputting XML fragments from the
// "InnerXml" and "OuterXml" properties in "XmlNode".

internal class XmlFragmentTextWriter : XmlTextWriter
{
        // Internal state.
        private StringWriter writer;

        // Constructor.
        public XmlFragmentTextWriter()
                        : base(writer = new StringWriter())
                        {
                                // Nothing to do here.
                        }

        // Close the fragment and return the final string.
        public override String ToString()
                        {
                                Close();
                                return writer.ToString();
                        }

        // Override some of the XmlTextWriter methods to handle namespaces 
better.
        public override void WriteStartAttribute
                                (String prefix, String localName, String ns)
                        {
                                if(ns == null || ns.Length == 0)
                                {
                                        if(prefix != null && prefix.Length != 0)
                                        {
                                                prefix = "";
                                        }
                                }
                                base.WriteStartAttribute(prefix, localName, ns);
                        }
        public override void WriteStartElement
                                (String prefix, String localName, String ns)
                        {
                                if(ns == null || ns.Length == 0)
                                {
                                        if(prefix != null && prefix.Length != 0)
                                        {
                                                prefix = "";
                                        }
                                }
                                base.WriteStartElement(prefix, localName, ns);
                        }

}; // class XmlFragmentTextWriter

}; // namespace System.Xml

--- NEW FILE ---
/*
 * XmlSpecialAttribute.cs - Implementation of the
 *              "System.Xml.XmlSpecialAttribute" class.
 *
 * Copyright (C) 2002 Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Xml
{

using System;

// Special attributes are used by "XmlTextReader" to access
// attributes on "XmlDeclaration" and similar nodes that don't
// normally have an attribute collection.

internal class XmlSpecialAttribute : XmlAttribute
{
        // Constructor.
        internal XmlSpecialAttribute(XmlNode parent, String name)
                        : base(parent, ConvertName(parent, name))
                        {
                                // Nothing to do here.
                        }

        // Convert a special name into a full "NameInfo" object.
        private static NameCache.NameInfo ConvertName(XmlNode parent, String 
name)
                        {
                                NameCache cache = 
parent.FindOwnerQuick().nameCache;
                                return cache.Add(name, String.Empty, 
String.Empty);
                        }

        // Determine if the attribute value was explictly specified.
        public override bool Specified
                        {
                                get
                                {
                                        return (Value != String.Empty);
                                }
                        }

        // Get or set the value associated with this node.
        public override String Value
                        {
                                get
                                {
                                        return 
parent.GetSpecialAttribute(LocalName);
                                }
                                set
                                {
                                        parent.SetSpecialAttribute(LocalName, 
value);
                                }
                        }

        // Clone this node in either shallow or deep mode.
        public override XmlNode CloneNode(bool deep)
                        {
                                // This should never be called in regular usage.
                                throw new NotImplementedException();
                        }

        // Writes the contents of this node to a specified XmlWriter.
        public override void WriteContentTo(XmlWriter w)
                        {
                                // This should never be called in regular usage.
                                throw new NotImplementedException();
                        }

        // Write this node and all of its contents to a specified XmlWriter.
        public override void WriteTo(XmlWriter w)
                        {
                                // This should never be called in regular usage.
                                throw new NotImplementedException();
                        }

}; // class XmlSpecialAttribute

}; // namespace System.Xml

Index: NodeList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/NodeList.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** NodeList.cs 21 Nov 2002 05:15:43 -0000      1.3
--- NodeList.cs 5 Dec 2002 22:19:53 -0000       1.4
***************
*** 29,38 ****
  {
        // Internal state.
!       private XmlNode first;
!       private XmlNode last;
!       private XmlNode nextSibling;
!       private XmlNode prevSibling;
!       private int count;
!       private int generation;
  
        // Create a new node list.
--- 29,38 ----
  {
        // Internal state.
!       internal XmlNode first;
!       internal XmlNode last;
!       internal XmlNode nextSibling;
!       internal XmlNode prevSibling;
!       internal int count;
!       internal int generation;
  
        // Create a new node list.
***************
*** 141,144 ****
--- 141,204 ----
                                        return null;
                                }
+                       }
+ 
+       // Insert a child into a node list just after a given node.
+       public void InsertAfter(XmlNode newNode, XmlNode refNode)
+                       {
+                               if(refNode != null)
+                               {
+                                       NodeList refList = GetList(refNode);
+                                       NodeList newList = GetList(newNode);
+                                       if(refList.nextSibling != null)
+                                       {
+                                               newList.nextSibling = 
refList.nextSibling;
+                                               newList.prevSibling = refNode;
+                                               refList.nextSibling = newNode;
+                                       }
+                                       else
+                                       {
+                                               refList.nextSibling = newNode;
+                                               newList.prevSibling = refNode;
+                                               last = newNode;
+                                       }
+                               }
+                               else if(first != null)
+                               {
+                                       GetList(first).prevSibling = newNode;
+                                       GetList(newNode).nextSibling = first;
+                               }
+                               else
+                               {
+                                       first = newNode;
+                                       last = newNode;
+                               }
+                               ++count;
+                               ++generation;
+                       }
+ 
+       // Remove a child from underneath its current parent.
+       public void RemoveChild(XmlNode node)
+                       {
+                               NodeList nodeList = GetList(node);
+                               if(nodeList.nextSibling != null)
+                               {
+                                       
GetList(nodeList.nextSibling).prevSibling =
+                                                       nodeList.prevSibling;
+                               }
+                               else
+                               {
+                                       last = nodeList.prevSibling;
+                               }
+                               if(nodeList.prevSibling != null)
+                               {
+                                       
GetList(nodeList.prevSibling).nextSibling =
+                                                       nodeList.nextSibling;
+                               }
+                               else
+                               {
+                                       first = nodeList.nextSibling;
+                               }
+                               --count;
+                               ++generation;
                        }
  

Index: XmlAttribute.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlAttribute.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** XmlAttribute.cs     3 Dec 2002 07:28:06 -0000       1.3
--- XmlAttribute.cs     5 Dec 2002 22:19:53 -0000       1.4
***************
*** 35,39 ****
        private NameCache.NameInfo name;
        internal char quoteChar;
-       internal XmlAttribute next;
  
        // Constructor.
--- 35,38 ----
***************
*** 43,56 ****
                                this.name = name;
                                this.quoteChar = '"';
-                               this.next = null;
-                       }
- 
-       // Get the attribute collection from the parent node.
-       internal override XmlAttributeCollection AttributesInternal
-                       {
-                               get
-                               {
-                                       return ParentNode.AttributesInternal;
-                               }
                        }
  
--- 42,45 ----
***************
*** 212,215 ****
--- 201,212 ----
                        {
                                // TODO
+                       }
+ 
+       // Determine if a particular node type can be inserted as
+       // a child of the current node.
+       internal override bool CanInsert(XmlNodeType type)
+                       {
+                               return (type == XmlNodeType.Text ||
+                                               type == 
XmlNodeType.EntityReference);
                        }
  

Index: XmlAttributeCollection.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlAttributeCollection.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** XmlAttributeCollection.cs   4 Dec 2002 04:46:35 -0000       1.3
--- XmlAttributeCollection.cs   5 Dec 2002 22:19:53 -0000       1.4
***************
*** 82,87 ****
                        }
  
!       // Get the position of a reference node within this collection
!       private int GetItemPosition(XmlAttribute refNode)
                        {
                                int count = Count;
--- 82,87 ----
                        }
  
!       // Get the index of a specific node within this collection.
!       internal int IndexOf(XmlAttribute refNode)
                        {
                                int count = Count;
***************
*** 93,96 ****
--- 93,107 ----
                                                return posn;
                                        }
+                               }
+                               return -1;
+                       }
+ 
+       // Get the position of a reference node within this collection.
+       private int GetItemPosition(XmlAttribute refNode)
+                       {
+                               int posn = IndexOf(refNode);
+                               if(posn != -1)
+                               {
+                                       return posn;
                                }
                                throw new ArgumentException

Index: XmlDeclaration.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDeclaration.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** XmlDeclaration.cs   4 Dec 2002 04:46:35 -0000       1.1
--- XmlDeclaration.cs   5 Dec 2002 22:19:53 -0000       1.2
***************
*** 37,40 ****
--- 37,41 ----
        private String standalone;
        private String version;
+       private XmlAttributeCollection attributes;
  
        // Constructor.
***************
*** 51,54 ****
--- 52,56 ----
                                }
                                this.version = version;
+                               this.attributes = null;
                        }
  
***************
*** 185,188 ****
--- 187,254 ----
                        {
                                w.WriteProcessingInstruction(Name, Value);
+                       }
+ 
+       // Get and set special attributes on this node.
+       internal override String GetSpecialAttribute(String name)
+                       {
+                               if(name == "version")
+                               {
+                                       return Version;
+                               }
+                               else if(name == "encoding")
+                               {
+                                       return Encoding;
+                               }
+                               else if(name == "standalone")
+                               {
+                                       return Standalone;
+                               }
+                               else
+                               {
+                                       return String.Empty;
+                               }
+                       }
+       internal override void SetSpecialAttribute(String name, String value)
+                       {
+                               if(name == "version")
+                               {
+                                       if(value != "1.0")
+                                       {
+                                               throw new ArgumentException
+                                                       
(S._("Xml_InvalidVersion"), "value");
+                                       }
+                               }
+                               else if(name == "encoding")
+                               {
+                                       Encoding = value;
+                               }
+                               else if(name == "standalone")
+                               {
+                                       Standalone = value;
+                               }
+                               else
+                               {
+                                       throw new ArgumentException
+                                               
(S._("Xml_InvalidSpecialAttribute"), "name");
+                               }
+                       }
+ 
+       // Get the internal attribute collection for this node.
+       internal override XmlAttributeCollection AttributesInternal
+                       {
+                               get
+                               {
+                                       if(attributes == null)
+                                       {
+                                               attributes = new 
XmlAttributeCollection(this);
+                                               attributes.Append
+                                                       (new 
XmlSpecialAttribute(this, "version"));
+                                               attributes.Append
+                                                       (new 
XmlSpecialAttribute(this, "encoding"));
+                                               attributes.Append
+                                                       (new 
XmlSpecialAttribute(this, "standalone"));
+                                       }
+                                       return attributes;
+                               }
                        }
  

Index: XmlDocument.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocument.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** XmlDocument.cs      4 Dec 2002 06:25:59 -0000       1.4
--- XmlDocument.cs      5 Dec 2002 22:19:53 -0000       1.5
***************
*** 34,42 ****
        private XmlImplementation implementation;
        private String baseURI;
-       private XmlElement root;
-       private XmlDocumentType docType;
        private bool preserveWhitespace;
        private XmlResolver xmlResolver;
!       private NameCache nameCache;
        internal XmlDocumentFragment placeholder;
        internal static readonly String xmlns = "http://www.w3.org/2000/xmlns/";;
--- 34,40 ----
        private XmlImplementation implementation;
        private String baseURI;
        private bool preserveWhitespace;
        private XmlResolver xmlResolver;
!       internal NameCache nameCache;
        internal XmlDocumentFragment placeholder;
        internal static readonly String xmlns = "http://www.w3.org/2000/xmlns/";;
***************
*** 77,82 ****
                        {
                                baseURI = String.Empty;
-                               root = null;
-                               docType = null;
                                preserveWhitespace = false;
                                placeholder = new XmlDocumentFragment(this);
--- 75,78 ----
***************
*** 93,96 ****
--- 89,107 ----
                        }
  
+       // Get a document child by type.
+       private XmlNode GetChildByType(XmlNodeType type)
+                       {
+                               XmlNode child = NodeList.GetFirstChild(this);
+                               while(child != null)
+                               {
+                                       if(child.NodeType == type)
+                                       {
+                                               return child;
+                                       }
+                                       child = NodeList.GetNextSibling(child);
+                               }
+                               return null;
+                       }
+ 
        // Get the root element for the document.
        public XmlElement DocumentElement
***************
*** 98,102 ****
                                get
                                {
!                                       return root;
                                }
                        }
--- 109,113 ----
                                get
                                {
!                                       return 
(XmlElement)(GetChildByType(XmlNodeType.Element));
                                }
                        }
***************
*** 107,111 ****
                                get
                                {
!                                       return docType;
                                }
                        }
--- 118,123 ----
                                get
                                {
!                                       return (XmlDocumentType)
!                                               
(GetChildByType(XmlNodeType.DocumentType));
                                }
                        }
***************
*** 694,697 ****
--- 706,856 ----
                                        break;
                                }
+                       }
+ 
+       // Determine if a particular node type can be inserted as
+       // a child of the current node.
+       internal override bool CanInsert(XmlNodeType type)
+                       {
+                               switch(type)
+                               {
+                                       case XmlNodeType.Element:
+                                       case XmlNodeType.DocumentType:
+                                       case XmlNodeType.XmlDeclaration:
+                                       {
+                                               return (GetChildByType(type) == 
null);
+                                       }
+                                       // Not reached.
+ 
+                                       case XmlNodeType.ProcessingInstruction:
+                                       case XmlNodeType.Comment:
+                                       case XmlNodeType.Whitespace:
+                                       {
+                                               return true;
+                                       }
+                                       // Not reached.
+ 
+                                       default: break;
+                               }
+                               return false;
+                       }
+ 
+       // Determine if a particular node type can be inserted after another,
+       // which may be null if the list is currently empty.
+       internal override bool CanInsertAfter(XmlNodeType type, XmlNode refNode)
+                       {
+                               // Filter out types that are definitely not 
allowed.
+                               if(!CanInsert(type))
+                               {
+                                       return false;
+                               }
+ 
+                               // If nothing in the list yet, then we can 
insert anything.
+                               if(refNode == null)
+                               {
+                                       return true;
+                               }
+ 
+                               // Handle special node categories.
+                               switch(type)
+                               {
+                                       case XmlNodeType.DocumentType:
+                                       {
+                                               // Must not have an element 
before this position.
+                                               while(refNode != null)
+                                               {
+                                                       if(refNode.NodeType == 
XmlNodeType.Element)
+                                                       {
+                                                               return false;
+                                                       }
+                                                       refNode = 
NodeList.GetPreviousSibling(refNode);
+                                               }
+                                       }
+                                       break;
+ 
+                                       case XmlNodeType.Element:
+                                       {
+                                               // Must not have a document 
type after this position.
+                                               refNode = 
NodeList.GetNextSibling(refNode);
+                                               while(refNode != null)
+                                               {
+                                                       if(refNode.NodeType == 
XmlNodeType.DocumentType)
+                                                       {
+                                                               return false;
+                                                       }
+                                                       refNode = 
NodeList.GetNextSibling(refNode);
+                                               }
+                                       }
+                                       break;
+ 
+                                       case XmlNodeType.XmlDeclaration:
+                                       {
+                                               // Xml declarations can never 
come after other nodes.
+                                               return false;
+                                       }
+                                       // Not reached.
+                               }
+ 
+                               // If we get here, then the node is allowed.
+                               return true;
+                       }
+ 
+       // Determine if a particular node type can be inserted before another,
+       // which may be null if the list is currently empty.
+       internal override bool CanInsertBefore(XmlNodeType type, XmlNode 
refNode)
+                       {
+                               // Filter out types that are definitely not 
allowed.
+                               if(!CanInsert(type))
+                               {
+                                       return false;
+                               }
+ 
+                               // If nothing in the list yet, then we can 
insert anything.
+                               if(refNode == null)
+                               {
+                                       return true;
+                               }
+ 
+                               // Handle special node categories.
+                               switch(type)
+                               {
+                                       case XmlNodeType.DocumentType:
+                                       {
+                                               // Must not have an element 
before this position.
+                                               refNode = 
NodeList.GetPreviousSibling(refNode);
+                                               while(refNode != null)
+                                               {
+                                                       if(refNode.NodeType == 
XmlNodeType.Element)
+                                                       {
+                                                               return false;
+                                                       }
+                                                       refNode = 
NodeList.GetPreviousSibling(refNode);
+                                               }
+                                       }
+                                       break;
+ 
+                                       case XmlNodeType.Element:
+                                       {
+                                               // Must not have a document 
type after this position.
+                                               while(refNode != null)
+                                               {
+                                                       if(refNode.NodeType == 
XmlNodeType.DocumentType)
+                                                       {
+                                                               return false;
+                                                       }
+                                                       refNode = 
NodeList.GetNextSibling(refNode);
+                                               }
+                                       }
+                                       break;
+ 
+                                       case XmlNodeType.XmlDeclaration:
+                                       {
+                                               // Xml declarations must come 
before everything else.
+                                               return (refNode == 
NodeList.GetFirstChild(this));
+                                       }
+                                       // Not reached.
+                               }
+ 
+                               // If we get here, then the node is allowed.
+                               return true;
                        }
  

Index: XmlDocumentFragment.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocumentFragment.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** XmlDocumentFragment.cs      3 Dec 2002 07:28:06 -0000       1.1
--- XmlDocumentFragment.cs      5 Dec 2002 22:19:53 -0000       1.2
***************
*** 133,136 ****
--- 133,160 ----
                        }
  
+       // Determine if a particular node type can be inserted as
+       // a child of the current node.
+       internal override bool CanInsert(XmlNodeType type)
+                       {
+                               switch(type)
+                               {
+                                       case XmlNodeType.Element:
+                                       case XmlNodeType.Text:
+                                       case XmlNodeType.CDATA:
+                                       case XmlNodeType.EntityReference:
+                                       case XmlNodeType.ProcessingInstruction:
+                                       case XmlNodeType.Comment:
+                                       case XmlNodeType.Whitespace:
+                                       case XmlNodeType.SignificantWhitespace:
+                                       {
+                                               return true;
+                                       }
+                                       // Not reached.
+ 
+                                       default: break;
+                               }
+                               return false;
+                       }
+ 
  }; // class XmlDocumentFragment
  

Index: XmlDocumentType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocumentType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** XmlDocumentType.cs  4 Dec 2002 04:46:35 -0000       1.2
--- XmlDocumentType.cs  5 Dec 2002 22:19:53 -0000       1.3
***************
*** 39,42 ****
--- 39,43 ----
        private XmlNamedNodeMap entities;
        private XmlNamedNodeMap notations;
+       private XmlAttributeCollection attributes;
  
        // Constructor.
***************
*** 57,60 ****
--- 58,62 ----
                                entities = new XmlNamedNodeMap(this);
                                notations = new XmlNamedNodeMap(this);
+                               attributes = null;
                        }
  
***************
*** 157,160 ****
--- 159,213 ----
                        {
                                w.WriteDocType(name, publicId, systemId, 
internalSubset);
+                       }
+ 
+       // Get and set special attributes on this node.
+       internal override String GetSpecialAttribute(String name)
+                       {
+                               if(name == "PUBLIC")
+                               {
+                                       return PublicId;
+                               }
+                               else if(name == "SYSTEM")
+                               {
+                                       return SystemId;
+                               }
+                               else
+                               {
+                                       return String.Empty;
+                               }
+                       }
+       internal override void SetSpecialAttribute(String name, String value)
+                       {
+                               XmlNameTable nt = FindOwnerQuick().NameTable;
+                               if(name == "PUBLIC")
+                               {
+                                       publicId = ((value != null) ? 
nt.Add(value) : String.Empty);
+                               }
+                               else if(name == "SYSTEM")
+                               {
+                                       systemId = ((value != null) ? 
nt.Add(value) : String.Empty);
+                               }
+                               else
+                               {
+                                       throw new ArgumentException
+                                               
(S._("Xml_InvalidSpecialAttribute"), "name");
+                               }
+                       }
+ 
+       // Get the internal attribute collection for this node.
+       internal override XmlAttributeCollection AttributesInternal
+                       {
+                               get
+                               {
+                                       if(attributes == null)
+                                       {
+                                               attributes = new 
XmlAttributeCollection(this);
+                                               attributes.Append
+                                                       (new 
XmlSpecialAttribute(this, "PUBLIC"));
+                                               attributes.Append
+                                                       (new 
XmlSpecialAttribute(this, "SYSTEM"));
+                                       }
+                                       return attributes;
+                               }
                        }
  

Index: XmlElement.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlElement.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** XmlElement.cs       4 Dec 2002 06:25:59 -0000       1.3
--- XmlElement.cs       5 Dec 2002 22:19:53 -0000       1.4
***************
*** 336,339 ****
--- 336,363 ----
                        }
  
+       // Determine if a particular node type can be inserted as
+       // a child of the current node.
+       internal override bool CanInsert(XmlNodeType type)
+                       {
+                               switch(type)
+                               {
+                                       case XmlNodeType.Element:
+                                       case XmlNodeType.Text:
+                                       case XmlNodeType.CDATA:
+                                       case XmlNodeType.EntityReference:
+                                       case XmlNodeType.ProcessingInstruction:
+                                       case XmlNodeType.Comment:
+                                       case XmlNodeType.Whitespace:
+                                       case XmlNodeType.SignificantWhitespace:
+                                       {
+                                               return true;
+                                       }
+                                       // Not reached.
+ 
+                                       default: break;
+                               }
+                               return false;
+                       }
+ 
  }; // class XmlElement
  

Index: XmlEntityReference.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlEntityReference.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** XmlEntityReference.cs       4 Dec 2002 06:25:59 -0000       1.1
--- XmlEntityReference.cs       5 Dec 2002 22:19:53 -0000       1.2
***************
*** 121,125 ****
                        }
  
! }; // class XmlElement
  
  }; // namespace System.Xml
--- 121,149 ----
                        }
  
!       // Determine if a particular node type can be inserted as
!       // a child of the current node.
!       internal override bool CanInsert(XmlNodeType type)
!                       {
!                               switch(type)
!                               {
!                                       case XmlNodeType.Element:
!                                       case XmlNodeType.Text:
!                                       case XmlNodeType.CDATA:
!                                       case XmlNodeType.EntityReference:
!                                       case XmlNodeType.ProcessingInstruction:
!                                       case XmlNodeType.Comment:
!                                       case XmlNodeType.Whitespace:
!                                       case XmlNodeType.SignificantWhitespace:
!                                       {
!                                               return true;
!                                       }
!                                       // Not reached.
! 
!                                       default: break;
!                               }
!                               return false;
!                       }
! 
! }; // class XmlEntityReference
  
  }; // namespace System.Xml

Index: XmlNode.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlNode.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** XmlNode.cs  4 Dec 2002 04:46:35 -0000       1.9
--- XmlNode.cs  5 Dec 2002 22:19:53 -0000       1.10
***************
*** 37,41 ****
        internal XmlNode  parent;
        internal NodeList list;
-       internal int depth;
  
        // Constructor.  Only accessible to internal subclasses.
--- 37,40 ----
***************
*** 44,55 ****
                                this.parent = parent;
                                this.list = null;               // Created on 
demand to save memory.
-                               if(parent != null)
-                               {
-                                       depth = parent.depth + 1;
-                               }
-                               else
-                               {
-                                       depth = 1;
-                               }
                        }
  
--- 43,46 ----
***************
*** 63,68 ****
                        }
  
!       // Get the attribute collection for node types that don't override
!       // "Attributes" according to the specification.
        internal virtual XmlAttributeCollection AttributesInternal
                        {
--- 54,60 ----
                        }
  
!       // Get an internal attribute collection.  This will also work on
!       // nodes such as "XmlDeclaration" that aren't normally specified
!       // to have an attribute collection like "XmlElement" nodes.
        internal virtual XmlAttributeCollection AttributesInternal
                        {
***************
*** 89,101 ****
                        }
  
-       // Determine if this node type can contain child nodes.
-       internal virtual bool CanHaveChildren
-                       {
-                               get
-                               {
-                                       return false;
-                               }
-                       }
- 
        // Get the children of this node.
        public virtual XmlNodeList ChildNodes
--- 81,84 ----
***************
*** 219,224 ****
                                get
                                {
!                                       // TODO
!                                       return null;
                                }
                                set
--- 202,208 ----
                                get
                                {
!                                       XmlFragmentTextWriter writer = new 
XmlFragmentTextWriter();
!                                       WriteContentTo(writer);
!                                       return writer.ToString();
                                }
                                set
***************
*** 333,338 ****
                                get
                                {
!                                       // TODO
!                                       return null;
                                }
                        }
--- 317,323 ----
                                get
                                {
!                                       XmlFragmentTextWriter writer = new 
XmlFragmentTextWriter();
!                                       WriteTo(writer);
!                                       return writer.ToString();
                                }
                        }
***************
*** 427,434 ****
                        {
                                XmlDocument doc;
!                               if(!CanHaveChildren)
                                {
                                        throw new InvalidOperationException
!                                               (S._("Xml_CannotHaveChildren"));
                                }
                                if(IsAncestorOf(newChild, this))
--- 412,422 ----
                        {
                                XmlDocument doc;
!                               XmlNode parentNode;
! 
!                               // Validate the parameters.
!                               if(!CanInsertAfter(newChild.NodeType, 
LastChild))
                                {
                                        throw new InvalidOperationException
!                                               (S._("Xml_CannotInsert"));
                                }
                                if(IsAncestorOf(newChild, this))
***************
*** 453,457 ****
                                        throw new 
ArgumentException(S._("Xml_ReadOnly"));
                                }
!                               // TODO: remove from original position and add 
to the new.
                                return newChild;
                        }
--- 441,481 ----
                                        throw new 
ArgumentException(S._("Xml_ReadOnly"));
                                }
! 
!                               // Remove the child from underneath its current 
parent.
!                               parentNode = newChild.ParentNode;
!                               if(parentNode != null)
!                               {
!                                       parentNode.RemoveChild(newChild);
!                               }
! 
!                               // If the node is a document fragment, then add 
its
!                               // children instead of the node itself.
!                               if(newChild.NodeType == 
XmlNodeType.DocumentFragment)
!                               {
!                                       XmlNode firstChild = 
NodeList.GetFirstChild(newChild);
!                                       XmlNode current, next;
!                                       current = firstChild;
!                                       while(current != null)
!                                       {
!                                               next = 
NodeList.GetNextSibling(current);
!                                               newChild.RemoveChild(current);
!                                               AppendChild(current);
!                                               current = next;
!                                       }
!                                       return firstChild;
!                               }
! 
!                               // Notify the document that we are about to do 
an insert.
!                               XmlNodeChangedEventArgs args;
!                               args = EmitBefore(XmlNodeChangedAction.Insert,
!                                                                 parentNode, 
this);
! 
!                               // Perform the insert.
!                               NodeList.GetList(this).InsertAfter(newChild, 
LastChild);
! 
!                               // Notify the document after the insert.
!                               EmitAfter(args);
! 
!                               // The child has been inserted into its new 
position.
                                return newChild;
                        }
***************
*** 473,476 ****
--- 497,501 ----
  
        // Implement the IXPathNavigator interface.
+       [TODO]
        public XPathNavigator CreateNavigator()
                        {
***************
*** 488,503 ****
        public virtual String GetNamespaceOfPrefix(String prefix)
                        {
!                               // TODO
!                               return null;
                        }
  
        // Get the prefix that corresponds to a particular namespace.
!       public virtual String GetPrefixOfNamespace(String prefix)
                        {
!                               // TODO
!                               return null;
                        }
  
        // Insert a new child under this node just after a reference child.
        public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
                        {
--- 513,634 ----
        public virtual String GetNamespaceOfPrefix(String prefix)
                        {
!                               // Bail out if no prefix supplied.
!                               if(prefix == null)
!                               {
!                                       return String.Empty;
!                               }
! 
!                               // Find the document that owns this node.
!                               XmlDocument doc = FindOwnerQuick();
!                               if(doc == null)
!                               {
!                                       return String.Empty;
!                               }
! 
!                               // Look up the prefix in the name table.  If it 
isn't
!                               // present in the table, then it won't be 
present in
!                               // the element node tree either.
!                               prefix = doc.NameTable.Get(prefix);
!                               if(prefix == null)
!                               {
!                                       return String.Empty;
!                               }
! 
!                               // Search for an element with this prefix.
!                               XmlNode node = this;
!                               XmlElement element;
!                               XmlAttributeCollection attributes;
!                               XmlAttribute attr;
!                               int posn, count;
!                               do
!                               {
!                                       if(node.NodeType == XmlNodeType.Element)
!                                       {
!                                               // If the node's name includes 
the prefix,
!                                               // then return the namespace 
for the node.
!                                               if(((Object)(node.Prefix)) == 
(Object)prefix)
!                                               {
!                                                       return 
node.NamespaceURI;
!                                               }
! 
!                                               // Is there an explicit 
"xmlns:prefix" declaration?
!                                               element = (XmlElement)node;
!                                               attributes = element.Attributes;
!                                               count = attributes.Count;
!                                               for(posn = 0; posn < count; 
++posn)
!                                               {
!                                                       attr = attributes[posn];
!                                                       
if(((Object)(attr.LocalName)) == (Object)prefix &&
!                                                          attr.Prefix == 
"xmlns")
!                                                       {
!                                                               return 
attr.Value;
!                                                       }
!                                               }
!                                       }
!                                       node = node.ParentNode;
!                               }
!                               while(node != null);
!                               return String.Empty;
                        }
  
        // Get the prefix that corresponds to a particular namespace.
!       public virtual String GetPrefixOfNamespace(String namespaceURI)
                        {
!                               // Find the document that owns this node.
!                               XmlDocument doc = FindOwnerQuick();
!                               if(doc == null)
!                               {
!                                       return String.Empty;
!                               }
! 
!                               // Handle the builtin "xmlns" namespace.
!                               if(namespaceURI == XmlDocument.xmlns)
!                               {
!                                       return "xmlns";
!                               }
! 
!                               // Look up the namespace in the name table.
!                               namespaceURI = doc.NameTable.Add(namespaceURI);
! 
!                               // Search for an element with this namespace.
!                               XmlNode node = this;
!                               XmlElement element;
!                               XmlAttributeCollection attributes;
!                               XmlAttribute attr;
!                               int posn, count;
!                               do
!                               {
!                                       if(node.NodeType == XmlNodeType.Element)
!                                       {
!                                               // If the node's name includes 
the namespace,
!                                               // then return the prefix for 
the node.
!                                               
if(((Object)(node.NamespaceURI)) ==
!                                                               
(Object)namespaceURI)
!                                               {
!                                                       return node.Prefix;
!                                               }
! 
!                                               // Is there an explicit 
"xmlns:prefix" declaration?
!                                               element = (XmlElement)node;
!                                               attributes = element.Attributes;
!                                               count = attributes.Count;
!                                               for(posn = 0; posn < count; 
++posn)
!                                               {
!                                                       attr = attributes[posn];
!                                                       if(attr.Prefix == 
"xmlns" &&
!                                                          attr.Value == 
namespaceURI)
!                                                       {
!                                                               return 
attr.LocalName;
!                                                       }
!                                               }
!                                       }
!                                       node = node.ParentNode;
!                               }
!                               while(node != null);
!                               return String.Empty;
                        }
  
        // Insert a new child under this node just after a reference child.
+       [TODO]
        public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
                        {
***************
*** 507,510 ****
--- 638,642 ----
  
        // Insert a new child under this node just before a reference child.
+       [TODO]
        public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
                        {
***************
*** 514,517 ****
--- 646,650 ----
  
        // Normalize the text nodes underneath this node.
+       [TODO]
        public virtual void Normalize()
                        {
***************
*** 522,526 ****
        public virtual XmlNode PrependChild(XmlNode newChild)
                        {
!                               // TODO
                                return newChild;
                        }
--- 655,725 ----
        public virtual XmlNode PrependChild(XmlNode newChild)
                        {
!                               XmlDocument doc;
!                               XmlNode parentNode;
! 
!                               // Validate the parameters.
!                               if(!CanInsertBefore(newChild.NodeType, 
FirstChild))
!                               {
!                                       throw new InvalidOperationException
!                                               (S._("Xml_CannotInsert"));
!                               }
!                               if(IsAncestorOf(newChild, this))
!                               {
!                                       throw new 
InvalidOperationException(S._("Xml_IsAncestor"));
!                               }
!                               if(this is XmlDocument)
!                               {
!                                       doc = (XmlDocument)this;
!                               }
!                               else
!                               {
!                                       doc = OwnerDocument;
!                               }
!                               if(newChild.OwnerDocument != doc)
!                               {
!                                       throw new ArgumentException
!                                               (S._("Xml_NotSameDocument"), 
"newChild");
!                               }
!                               if(IsReadOnly)
!                               {
!                                       throw new 
ArgumentException(S._("Xml_ReadOnly"));
!                               }
! 
!                               // Remove the child from underneath its current 
parent.
!                               parentNode = newChild.ParentNode;
!                               if(parentNode != null)
!                               {
!                                       parentNode.RemoveChild(newChild);
!                               }
! 
!                               // If the node is a document fragment, then add 
its
!                               // children instead of the node itself.
!                               if(newChild.NodeType == 
XmlNodeType.DocumentFragment)
!                               {
!                                       XmlNode lastChild = 
NodeList.GetLastChild(newChild);
!                                       XmlNode current, next;
!                                       current = lastChild;
!                                       while(current != null)
!                                       {
!                                               next = 
NodeList.GetPreviousSibling(current);
!                                               newChild.RemoveChild(current);
!                                               PrependChild(current);
!                                               current = next;
!                                       }
!                                       return lastChild;
!                               }
! 
!                               // Notify the document that we are about to do 
an insert.
!                               XmlNodeChangedEventArgs args;
!                               args = EmitBefore(XmlNodeChangedAction.Insert,
!                                                                 parentNode, 
this);
! 
!                               // Perform the insert.
!                               NodeList.GetList(this).InsertAfter(newChild, 
null);
! 
!                               // Notify the document after the insert.
!                               EmitAfter(args);
! 
!                               // The child has been inserted into its new 
position.
                                return newChild;
                        }
***************
*** 529,533 ****
        public virtual void RemoveAll()
                        {
!                               // TODO
                        }
  
--- 728,739 ----
        public virtual void RemoveAll()
                        {
!                               XmlNode current = FirstChild;
!                               XmlNode next;
!                               while(current != null)
!                               {
!                                       next = NodeList.GetNextSibling(current);
!                                       RemoveChild(current);
!                                       current = next;
!                               }
                        }
  
***************
*** 535,543 ****
        public virtual XmlNode RemoveChild(XmlNode oldChild)
                        {
!                               // TODO
                                return oldChild;
                        }
  
        // Replace a child of this node.
        public virtual XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild)
                        {
--- 741,767 ----
        public virtual XmlNode RemoveChild(XmlNode oldChild)
                        {
!                               // Validate the parameters.
!                               if(oldChild.ParentNode != this)
!                               {
!                                       throw new ArgumentException
!                                               (S._("Xml_CannotRemove"), 
"oldChild");
!                               }
! 
!                               // Notify the document that we are about to do 
a remove.
!                               XmlNodeChangedEventArgs args;
!                               args = EmitBefore(XmlNodeChangedAction.Remove, 
this, null);
! 
!                               // Remove the child.
!                               NodeList.GetList(this).RemoveChild(oldChild);
! 
!                               // Notify the document after the remove.
!                               EmitAfter(args);
! 
!                               // Return the child that was removed.
                                return oldChild;
                        }
  
        // Replace a child of this node.
+       [TODO]
        public virtual XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild)
                        {
***************
*** 547,550 ****
--- 771,775 ----
  
        // Select a list of nodes matching a particular XPath expression.
+       [TODO]
        public XmlNodeList SelectNodes(String xpath)
                        {
***************
*** 554,557 ****
--- 779,783 ----
  
        // Select a list of nodes matching a particular XPath expression.
+       [TODO]
        public XmlNodeList SelectNodes(String xpath, XmlNamespaceManager nsmgr)
                        {
***************
*** 561,564 ****
--- 787,791 ----
  
        // Select a single node matching a particular XPath expression.
+       [TODO]
        public XmlNode SelectSingleNode(String xpath)
                        {
***************
*** 568,571 ****
--- 795,799 ----
  
        // Select a single node matching a particular XPath expression.
+       [TODO]
        public XmlNode SelectSingleNode(String xpath, XmlNamespaceManager nsmgr)
                        {
***************
*** 595,598 ****
--- 823,827 ----
  
        // Clone the children from another node into this node.
+       [TODO]
        internal void CloneChildrenFrom(XmlNode other, bool deep)
                        {
***************
*** 661,664 ****
--- 890,925 ----
                                        FindOwnerQuick().EmitAfter(args);
                                }
+                       }
+ 
+       // Get and set special attributes on this node.
+       internal virtual String GetSpecialAttribute(String name)
+                       {
+                               // Nothing to do here.
+                               return String.Empty;
+                       }
+       internal virtual void SetSpecialAttribute(String name, String value)
+                       {
+                               // Nothing to do here.
+                       }
+ 
+       // Determine if a particular node type can be inserted as
+       // a child of the current node.
+       internal virtual bool CanInsert(XmlNodeType type)
+                       {
+                               return false;
+                       }
+ 
+       // Determine if a particular node type can be inserted after another,
+       // which may be null if the list is currently empty.
+       internal virtual bool CanInsertAfter(XmlNodeType type, XmlNode refNode)
+                       {
+                               return CanInsert(type);
+                       }
+ 
+       // Determine if a particular node type can be inserted before another,
+       // which may be null if the list is currently empty.
+       internal virtual bool CanInsertBefore(XmlNodeType type, XmlNode refNode)
+                       {
+                               return CanInsert(type);
                        }
  

Index: XmlTextReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextReader.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** XmlTextReader.cs    3 Dec 2002 03:48:29 -0000       1.8
--- XmlTextReader.cs    5 Dec 2002 22:19:53 -0000       1.9
***************
*** 36,39 ****
--- 36,40 ----
        private XmlNameTable nameTable;
        private XmlNamespaceManager namespaceManager;
+       private XmlDocument document;
        private ReadState readState;
        private WhitespaceHandling whitespace;
***************
*** 47,50 ****
--- 48,53 ----
        private Encoding encoding;
        private XmlNode currentNode;
+       private XmlNode contextNode;
+       private int ungetch;
  
        // Constructors.
***************
*** 61,67 ****
                                }
                                namespaces = true;
                                nameTable = nt;
                                namespaceManager = new XmlNamespaceManager(nt);
!                               normalize = false;
                                readState = ReadState.Initial;
                                whitespace = WhitespaceHandling.All;
--- 64,71 ----
                                }
                                namespaces = true;
+                               normalize = false;
                                nameTable = nt;
                                namespaceManager = new XmlNamespaceManager(nt);
!                               document = new XmlDocument(nt);
                                readState = ReadState.Initial;
                                whitespace = WhitespaceHandling.All;
***************
*** 74,77 ****
--- 78,83 ----
                                encoding = null;
                                currentNode = null;
+                               contextNode = document;
+                               ungetch = -1;
                        }
        public XmlTextReader(Stream input)
***************
*** 288,295 ****
--- 294,312 ----
                        }
  
+       // Synchronize on an element if the current is an attribute.
+       private void SyncOnElement()
+                       {
+                               XmlAttribute attr = (currentNode as 
XmlAttribute);
+                               if(attr != null)
+                               {
+                                       currentNode = attr.parent;
+                               }
+                       }
+ 
        // Move the current position to a particular attribute.
        public override void MoveToAttribute(int i)
                        {
                                XmlAttributeCollection attributes;
+                               SyncOnElement();
                                if(currentNode == null)
                                {
***************
*** 321,324 ****
--- 338,342 ----
                                        return false;
                                }
+                               SyncOnElement();
                                attributes = currentNode.AttributesInternal;
                                if(attributes != null)
***************
*** 343,346 ****
--- 361,365 ----
                                        return false;
                                }
+                               SyncOnElement();
                                attributes = currentNode.AttributesInternal;
                                if(attributes != null)
***************
*** 377,380 ****
--- 396,400 ----
                                if(currentNode != null)
                                {
+                                       SyncOnElement();
                                        attributes = 
currentNode.AttributesInternal;
                                        if(attributes != null && 
attributes.Count > 0)
***************
*** 391,401 ****
                        {
                                XmlAttribute attr = (currentNode as 
XmlAttribute);
                                if(attr != null)
                                {
!                                       attr = attr.next;
!                                       if(attr != null)
                                        {
!                                               currentNode = attr;
!                                               return true;
                                        }
                                        else
--- 411,431 ----
                        {
                                XmlAttribute attr = (currentNode as 
XmlAttribute);
+                               XmlAttributeCollection attributes;
+                               int index;
                                if(attr != null)
                                {
!                                       attributes = 
currentNode.ParentNode.AttributesInternal;
!                                       if(attributes != null)
                                        {
!                                               index = 
attributes.IndexOf(attr) + 1;
!                                               if(index <= 0 || index >= 
attributes.Count)
!                                               {
!                                                       return false;
!                                               }
!                                               else
!                                               {
!                                                       currentNode = 
attributes[index];
!                                                       return true;
!                                               }
                                        }
                                        else
***************
*** 410,419 ****
                        }
  
        // Read the next node in the input stream.
        [TODO]
        public override bool Read()
                        {
!                               // TODO
                                return false;
                        }
  
--- 440,639 ----
                        }
  
+       // Read the next character.
+       private int ReadChar()
+                       {
+                               if(ungetch != -1)
+                               {
+                                       int ch = ungetch;
+                                       ungetch = -1;
+                                       return ch;
+                               }
+                               else
+                               {
+                                       return reader.Read();
+                               }
+                       }
+ 
+       // Unget the last character to be read again next time.
+       private void UngetChar(int ch)
+                       {
+                               ungetch = ch;
+                       }
+ 
        // Read the next node in the input stream.
        [TODO]
        public override bool Read()
                        {
!                               int ch;
!                               StringBuilder builder;
!                               int count;
! 
!                               // Validate the current state of the stream.
!                               if(readState == ReadState.EndOfFile)
!                               {
!                                       return false;
!                               }
!                               else if(reader == null)
!                               {
!                                       throw new 
XmlException(S._("Xml_ReaderClosed"));
!                               }
!                               else if(readState == ReadState.Error)
!                               {
!                                       throw new 
XmlException(S._("Xml_ReaderError"));
!                               }
! 
!                               // Skip white space in the input stream.  TODO: 
collect
!                               // up significant white space.
!                               ++linePosition;
!                               while((ch = ReadChar()) != -1)
!                               {
!                                       if(!Char.IsWhiteSpace((char)ch))
!                                       {
!                                               break;
!                                       }
!                                       if(ch == '\n')
!                                       {
!                                               ++lineNumber;
!                                               linePosition = 1;
!                                       }
!                                       else
!                                       {
!                                               ++linePosition;
!                                       }
!                               }
!                               if(ch == -1)
!                               {
!                                       // We've reached the end of the stream. 
 Throw
!                                       // an error if we haven't closed all 
elements.
!                                       // TODO: error handling
!                                       --linePosition;
!                                       readState = ReadState.EndOfFile;
!                                       currentNode = null;
!                                       return false;
!                               }
! 
!                               // Determine what to do based on the next 
character.
!                               if(ch == '<')
!                               {
!                                       // Some kind of tag.
!                                       ++linePosition;
!                                       ch = ReadChar();
!                                       if(ch == '/')
!                                       {
!                                               // End element tag.
!                                               // TODO
!                                       }
!                                       else if(ch == '!')
!                                       {
!                                               // Comment, CDATA, or document 
type information.
!                                               ++linePosition;
!                                               ch = ReadChar();
!                                               if(ch == '-')
!                                               {
!                                                       // Parse the "<!--" 
comment start sequence.
!                                                       ++linePosition;
!                                                       ch = ReadChar();
!                                                       if(ch != '-')
!                                                       {
!                                                               goto error;
!                                                       }
! 
!                                                       // Search for the "-->" 
comment end sequence.
!                                                       builder = new 
StringBuilder();
!                                                       ++linePosition;
!                                                       count = 0;
!                                                       while((ch = ReadChar()) 
!= -1)
!                                                       {
!                                                               
builder.Append((char)ch);
!                                                               if(ch == '-')
!                                                               {
!                                                                       ++count;
!                                                               }
!                                                               else if(ch == 
'>')
!                                                               {
!                                                                       
if(count >= 2)
!                                                                       {
!                                                                               
builder.Remove(builder.Length - 3, 3);
!                                                                               
break;
!                                                                       }
!                                                                       count = 
0;
!                                                               }
!                                                               else
!                                                               {
!                                                                       count = 
0;
!                                                               }
!                                                               if(ch == '\n')
!                                                               {
!                                                                       
++lineNumber;
!                                                                       
linePosition = 1;
!                                                               }
!                                                               else
!                                                               {
!                                                                       
++linePosition;
!                                                               }
!                                                       }
!                                                       if(ch != '>')
!                                                       {
!                                                               goto error;
!                                                       }
! 
!                                                       // Create a comment 
node and return.
!                                                       currentNode = 
document.CreateComment
!                                                               
(builder.ToString());
!                                                       try
!                                                       {
!                                                               
contextNode.AppendChild(currentNode);
!                                                       }
!                                                       
catch(InvalidOperationException)
!                                                       {
!                                                               readState = 
ReadState.Error;
!                                                               currentNode = 
null;
!                                                               throw new 
XmlException(S._("Xml_ReaderError"));
!                                                       }
!                                                       return true;
!                                               }
!                                               else if(ch == '[')
!                                               {
!                                                       // TODO: CDATA and 
document type nodes.
!                                               }
!                                               else
!                                               {
!                                                       goto error;
!                                               }
!                                       }
!                                       else if(ch == '?')
!                                       {
!                                               // Processing instruction.
!                                               // TODO
!                                       }
!                                       else 
if(XmlConvert.IsNameStart((char)ch, true))
!                                       {
!                                               // Start element tag.
!                                               // TODO
!                                       }
!                                       else
!                                       {
!                                               goto error;
!                                       }
!                               }
!                               else
!                               {
!                                       // Text and entity references.
!                                       // TODO
!                               }
! 
                                return false;
+ 
+                               // We jump to here if some kind of parse error 
occurred
+                               // on the last character that we read.
+                       error:
+                               --linePosition;
+                               if(ch != -1)
+                               {
+                                       UngetChar(ch);
+                               }
+                               readState = ReadState.Error;
+                               currentNode = null;
+                               throw new XmlException(S._("Xml_ReaderError"));
                        }
  
***************
*** 493,500 ****
                                get
                                {
!                                       XmlElement element = (currentNode as 
XmlElement);
!                                       if(element != null)
                                        {
!                                               return element.Attributes.Count;
                                        }
                                        else
--- 713,733 ----
                                get
                                {
!                                       XmlAttributeCollection attributes;
!                                       XmlAttribute attr = (currentNode as 
XmlAttribute);
!                                       if(attr != null)
                                        {
!                                               attributes = 
attr.ParentNode.AttributesInternal;
!                                       }
!                                       else if(currentNode != null)
!                                       {
!                                               attributes = 
currentNode.AttributesInternal;
!                                       }
!                                       else
!                                       {
!                                               return 0;
!                                       }
!                                       if(attributes != null)
!                                       {
!                                               return attributes.Count;
                                        }
                                        else
***************
*** 519,530 ****
                                get
                                {
!                                       if(currentNode != null)
                                        {
!                                               return currentNode.depth;
!                                       }
!                                       else
!                                       {
!                                               return 0;
                                        }
                                }
                        }
--- 752,764 ----
                                get
                                {
!                                       XmlNode node = currentNode;
!                                       int depth = 0;
!                                       while(node != null && !(node is 
XmlDocument) &&
!                                             !(node is XmlDocumentFragment))
                                        {
!                                               ++depth;
!                                               node = node.parent;
                                        }
+                                       return depth;
                                }
                        }





reply via email to

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