2003-03-15 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Sat, 15 Mar 2003 08:35:39 +0000 (08:35 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sat, 15 Mar 2003 08:35:39 +0000 (08:35 -0000)
* XmlConstructs.cs : fix "int IsXXX()" to reject negative value.
* XmlDocument.cs : simplify Load(string url) to use XmlTextReader.
  fixed ReadNode(), it should call reader.Read() only on Initial state.
* XmlInputStream.cs : Changed namespace. Added XmlStreamReader(stream)
  and XmlStreamReader (string). Fixed XmlInputStream(url) not to use
  System.Net.WebClient directly.
* XmlParserContext.cs : baseURI don't be null.
* XmlTextWriter.cs : use WebName for Encoding instead of HeaderName.
* XmlUrlResolver.cs : namespace change for XmlInputStream.

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

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlConstructs.cs
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlInputStream.cs
mcs/class/System.XML/System.Xml/XmlParserContext.cs
mcs/class/System.XML/System.Xml/XmlTextWriter.cs
mcs/class/System.XML/System.Xml/XmlUrlResolver.cs

index 6b31527c3183da07b8326b16a3ef21a7a874fdd2..7d5b9fa72fa8f71adef31da0e7ab636099f044c0 100644 (file)
@@ -1,3 +1,15 @@
+2003-03-15  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * XmlConstructs.cs : fix "int IsXXX()" to reject negative value.
+       * XmlDocument.cs : simplify Load(string url) to use XmlTextReader.
+         fixed ReadNode(), it should call reader.Read() only on Initial state.
+       * XmlInputStream.cs : Changed namespace. Added XmlStreamReader(stream)
+         and XmlStreamReader (string). Fixed XmlInputStream(url) not to use
+         System.Net.WebClient directly.
+       * XmlParserContext.cs : baseURI don't be null.
+       * XmlTextWriter.cs : use WebName for Encoding instead of HeaderName.
+       * XmlUrlResolver.cs : namespace change for XmlInputStream.
+
 2003-03-12  Elan Feingold <efeingold@mn.rr.com>
 
        * XmlTextReader.cs: When throwing a ReaderException, show what
index ad297c06f275ef2c6a458bb158f61ab5c7818e33..f8b41cdee440f89af8417fb77e667a8aecac4137 100755 (executable)
@@ -366,7 +366,7 @@ namespace System.Xml
 \r
                public static bool IsSpace(int c) \r
                {\r
-                       return (CHARS[c] & SPACE) != 0;\r
+                       return c > 0 && (CHARS[c] & SPACE) != 0;\r
                }\r
 \r
                /// <summary>\r
@@ -381,7 +381,7 @@ namespace System.Xml
 \r
                public static bool IsNameStart(int c) \r
                {\r
-                       return (CHARS[c] & NAME_START) != 0;\r
+                       return c > 0 && (CHARS[c] & NAME_START) != 0;\r
                } \r
 \r
                /// <summary>\r
@@ -396,7 +396,7 @@ namespace System.Xml
 \r
                public static bool IsName(int c) \r
                {\r
-                       return (CHARS[c] & NAME) != 0;\r
+                       return c > 0 && (CHARS[c] & NAME) != 0;\r
                } \r
 \r
                /// <summary>\r
@@ -425,7 +425,7 @@ namespace System.Xml
 \r
                public static bool IsNCName(int c) \r
                {\r
-                       return (CHARS[c] & NCNAME) != 0;\r
+                       return c > 0 && (CHARS[c] & NCNAME) != 0;\r
                } \r
 \r
                /// <summary>\r
@@ -440,7 +440,7 @@ namespace System.Xml
 \r
                public static bool IsPubid(int c) \r
                {\r
-                       return (CHARS[c] & PUBID) != 0;\r
+                       return c > 0 && (CHARS[c] & PUBID) != 0;\r
                }\r
 \r
                /// <summary>\r
index 7b8e589e08188838f7576ebc60a6c1ce6dfac682..fcf8d9b17b98b2b68f143a51db5e66d43264f648 100644 (file)
@@ -20,6 +20,7 @@ using System.Text;
 using System.Xml.XPath;
 using System.Diagnostics;
 using System.Collections;
+using Mono.Xml.Native;
 
 namespace System.Xml
 {
@@ -558,18 +559,7 @@ namespace System.Xml
 
                public virtual void Load (string filename)
                {
-                       //HACK, HACK
-                       if (filename.IndexOf (':') != -1) {
-                               // While we fix Uri the code that uses it is only triggered by a colon in the filename.
-                               Uri uri = new Uri (filename);
-                               baseURI = filename;     // FIXME: resolve base
-                               Stream stream = new XmlUrlResolver ().GetEntity (uri, null, typeof(Stream)) as Stream;
-                               XmlReader xmlReader = new XmlTextReader (new XmlStreamReader (new XmlInputStream (stream)));
-                               Load (xmlReader);
-                       } else {
-                               //Remove this once Uri.Parse is fixed.
-                               Load (File.OpenRead (filename));
-                       }
+                       Load (new XmlTextReader (filename));
                }
 
                public virtual void Load (TextReader txtReader)
@@ -702,26 +692,23 @@ namespace System.Xml
                        XmlNode resultNode = null;
                        XmlNode newNode = null;
                        XmlNode currentNode = null;
+
+                       if (reader.ReadState == ReadState.Initial)
+                               reader.Read ();
+
                        // It was originally XmlDocument.Load(reader reader) when mcs was v0.16.
                        int startDepth = reader.Depth;
-                       bool atStart = true;
+//                     bool atStart = true;
                        bool ignoredWhitespace;
                        bool reachedEOF = false;
 
                        do {
                                ignoredWhitespace = false;
-                               reader.Read ();
                                if (reader.NodeType == XmlNodeType.None)
                                        if (reachedEOF)
                                                throw new Exception ("XML Reader reached to end while reading node.");
                                        else
                                                reachedEOF = true;
-                               // This complicated check is because we shouldn't make
-                               // improper additional XmlReader.Read() by this method itself.
-                               if(atStart && (reader.NodeType == XmlNodeType.EndElement || 
-                                       reader.NodeType == XmlNodeType.EndEntity))
-                                       throw new InvalidOperationException ("the XmlReader now holds invalid position.");
-                               atStart = false;
                                switch (reader.NodeType) {
 
                                case XmlNodeType.Attribute:
@@ -761,7 +748,7 @@ namespace System.Xml
                                        break;
 
                                case XmlNodeType.EndElement:
-                                       if(currentNode.Name != reader.Name)
+                                       if(currentNode == null || currentNode.Name != reader.Name)
                                                throw new XmlException ("mismatch end tag.");
                                        currentNode = currentNode.ParentNode;
                                        break;
@@ -828,12 +815,9 @@ namespace System.Xml
                                                ignoredWhitespace = true;
                                        break;
                                }
-                       } while ((!reader.EOF && ignoredWhitespace) ||
-                               reader.Depth > startDepth || 
-                               // This complicated condition is because reader.Depth was set
-                               // before XmlTextReader.depth increments ;-)
-                               (reader.Depth == startDepth && reader.NodeType == XmlNodeType.Element && reader.IsEmptyElement == false)
-                               );
+                               reader.Read ();
+                       } while (ignoredWhitespace || reader.Depth > startDepth ||
+                               (reader.Depth == startDepth && reader.NodeType == XmlNodeType.EndElement));
                        return resultNode != null ? resultNode : newNode;
                }
 
index f5b75fd0114dbaae0273a00294d3ac8e0c7ab62f..1b23ffae588da99fdd347c3dc65062c7b9e5f4d6 100644 (file)
 using System;\r
 using System.IO;\r
 using System.Text;\r
+using System.Xml;\r
 \r
-namespace System.Xml\r
+namespace Mono.Xml.Native\r
 {\r
        #region XmlStreamReader
-       internal class XmlStreamReader : StreamReader
+       public class XmlStreamReader : StreamReader
        {
                public XmlStreamReader (XmlInputStream input)
                        : base (input, input.ActualEncoding != null ? input.ActualEncoding : Encoding.UTF8)
                {
                }
+
+               public XmlStreamReader (Stream input)
+                       : this (new XmlInputStream (input))
+               {
+               }
+
+               public XmlStreamReader (string url)
+                       : this (new XmlInputStream (url))
+               {
+               }
        }
        #endregion
 \r
@@ -33,9 +44,18 @@ namespace System.Xml
 \r
                static XmlException encodingException = new XmlException ("invalid encoding specification.");\r
 \r
-               public XmlInputStream (string uri)\r
+               public XmlInputStream (string url)\r
                {\r
-                       Initialize (new System.Net.WebClient ().OpenRead (uri));\r
+#if NetworkEnabled\r
+                       try {\r
+                               Uri uri = new Uri (url);\r
+                               Initialize (new MemoryStream (new System.Net.WebClient ().DownloadData (url)));\r
+                       } catch (UriFormatException ex) {\r
+                               Initialize (new FileStream (url, FileMode.Open));\r
+                       }\r
+#else\r
+                       Initialize (new FileStream (url, FileMode.Open));\r
+#endif\r
                }\r
 \r
                public XmlInputStream (Stream stream)\r
index 58c5536a6d128a84c07f9439d4afcf225cde7b95..57bfa643846ca5d8c609e6c3efc433bddc79989b 100644 (file)
@@ -106,7 +106,7 @@ namespace System.Xml
                        this.publicID = pubId;
                        this.systemID = sysId;
                        this.internalSubset = internalSubset;
-                       this.baseURI = baseURI;
+                       this.baseURI = baseURI != null ? baseURI : String.Empty;
                        this.xmlLang = xmlLang;
                        this.xmlSpace = xmlSpace;
                        this.encoding = enc;
index 200b921fe063fa004a10570cf0add9c09c626ea2..eb0cf3b1ca4e44293e6f1275616d7d7580f582b9 100644 (file)
@@ -6,6 +6,9 @@
 //
 // (C) 2002 Kral Ferch
 //
+// [FIXME]
+// Document state should be considered.
+//
 
 using System;
 using System.Collections;
@@ -597,7 +600,7 @@ namespace System.Xml
                        string encodingFormatting = "";
 
                        if (!nullEncoding) 
-                               encodingFormatting = String.Format (" encoding={0}{1}{0}", quoteChar, w.Encoding.HeaderName);
+                               encodingFormatting = String.Format (" encoding={0}{1}{0}", quoteChar, w.Encoding.WebName);
 
                        w.Write("<?xml version={0}1.0{0}{1}{2}?>", quoteChar, encodingFormatting, standaloneFormatting);
                        ws = WriteState.Prolog;
index 2b2c41f78fb717c03ebac3f75f0e7ce97a02d083..a7b214be56d3cece96c9afa3f006ace064044732 100755 (executable)
@@ -8,6 +8,7 @@
 
 using System.Net;
 using System.IO;
+using Mono.Xml.Native;
 
 namespace System.Xml
 {