2003-02-27 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 26 Feb 2003 19:11:46 +0000 (19:11 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 26 Feb 2003 19:11:46 +0000 (19:11 -0000)
* XmlDocument.cs: modified Load().
  Uri.Parse might not allow non-uri string.
* XmlInputStream.cs: patch by Gonzalo (CanSeek).
  added some constructors for convenience.
* XmlTextReader.cs: modified some constructors.

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

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlInputStream.cs
mcs/class/System.XML/System.Xml/XmlTextReader.cs

index ca0191fb2714c2e4e80b81909fbe93cd226f85ef..8147c6c12a6cedbfdc1de3bcdf4ca17c4a22538c 100644 (file)
@@ -1,3 +1,11 @@
+2003-02-27  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * XmlDocument.cs: modified Load().
+         Uri.Parse might not allow non-uri string.
+       * XmlInputStream.cs: patch by Gonzalo (CanSeek).
+         added some constructors for convenience.
+       * XmlTextReader.cs: modified some constructors.
+
 2003-02-18  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * XmlDocument.cs:
index 7b8e589e08188838f7576ebc60a6c1ce6dfac682..8499260d5c7a0f72e2f5d636c355b884d0ea561c 100644 (file)
@@ -552,24 +552,12 @@ namespace System.Xml
 
                public virtual void Load (Stream inStream)
                {
-                       XmlReader xmlReader = new XmlTextReader (new XmlInputStream (inStream));
-                       Load (xmlReader);
+                       Load (new XmlTextReader (new XmlStreamReader (inStream)));
                }
 
                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 (new XmlStreamReader (filename)));
                }
 
                public virtual void Load (TextReader txtReader)
@@ -577,6 +565,7 @@ namespace System.Xml
                        Load (new XmlTextReader (txtReader));
                }
 
+               [MonoTODO("XmlValidatingReader should be used.")]
                public virtual void Load (XmlReader xmlReader)
                {
                        // Reset our document
@@ -585,6 +574,8 @@ namespace System.Xml
                        // like properties we have, etc.
                        RemoveAll ();
 
+                       this.baseURI = xmlReader.BaseURI;
+
                        // create all contents with use of ReadNode()
                        do {
                                XmlNode n = ReadNode (xmlReader);
index f5b75fd0114dbaae0273a00294d3ac8e0c7ab62f..19161978f8b48238a4756a735e5093d50e34668f 100644 (file)
@@ -1,27 +1,37 @@
-//
-// System.Xml.XmlInputStream 
-//     encoding-specification-wise XML input stream and reader
-//
-// Author:
-//     Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
-//
-//     (C)2003 Atsushi Enomoto
-//
+//\r
+// System.Xml.XmlInputStream \r
+//     encoding-specification-wise XML input stream and reader\r
+//\r
+// Author:\r
+//     Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)\r
+//\r
+//     (C)2003 Atsushi Enomoto\r
+//\r
 using System;\r
 using System.IO;\r
 using System.Text;\r
 \r
 namespace System.Xml\r
 {\r
-       #region XmlStreamReader
-       internal class XmlStreamReader : StreamReader
-       {
-               public XmlStreamReader (XmlInputStream input)
-                       : base (input, input.ActualEncoding != null ? input.ActualEncoding : Encoding.UTF8)
-               {
-               }
-       }
-       #endregion
+       #region XmlStreamReader\r
+       internal class XmlStreamReader : StreamReader\r
+       {\r
+               public XmlStreamReader (XmlInputStream input)\r
+                       : base (input, input.ActualEncoding != null ? input.ActualEncoding : Encoding.UTF8)\r
+               {\r
+               }\r
+\r
+               public XmlStreamReader (Stream stream)\r
+                       : this (new XmlInputStream (stream))\r
+               {\r
+               }\r
+\r
+               public XmlStreamReader (string url)\r
+                       : this (new XmlInputStream (url))\r
+               {\r
+               }\r
+       }\r
+       #endregion\r
 \r
        public class XmlInputStream : Stream\r
        {\r
@@ -33,9 +43,17 @@ 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
+                       Stream stream = null;\r
+                       try {\r
+                               Uri uriObj = new Uri (url);\r
+                               stream = new System.Net.WebClient ().OpenRead (url);\r
+                       } catch (UriFormatException) {\r
+                       }\r
+                       if (stream == null)\r
+                               stream = File.OpenRead (url);\r
+                       Initialize (stream);\r
                }\r
 \r
                public XmlInputStream (Stream stream)\r
@@ -114,8 +132,8 @@ namespace System.Xml
                                        if (c == 'e') {\r
                                                ms.WriteByte ((byte)'e');\r
                                                size = stream.Read (buffer, 0, 7);\r
-                                               ms.Write (buffer, 0, 7);\r
-                                               if (Encoding.ASCII.GetString(buffer, 0, 7) == "ncoding") {\r
+                                               ms.Write (buffer, 0, size);\r
+                                               if (size == 7 && Encoding.ASCII.GetString(buffer, 0, 7) == "ncoding") {\r
                                                        c = this.SkipWhitespace(ms);\r
                                                        if (c != '=')\r
                                                                throw encodingException;\r
@@ -138,12 +156,14 @@ namespace System.Xml
                                                        ms.WriteByte ((byte)quoteChar);\r
                                                        enc = Encoding.GetEncoding (encodingName);\r
                                                }\r
-                                               else\r
-                                                       ms.Write (buffer, 0, size);\r
                                        }\r
                                        else\r
                                                ms.WriteByte ((byte)c);\r
                                }\r
+\r
+                               if (enc == null)\r
+                                       enc = Encoding.Default;\r
+\r
                                buffer = ms.ToArray ();\r
                                bufLength = buffer.Length;\r
                                bufPos = 0;\r
@@ -188,7 +208,7 @@ namespace System.Xml
                }\r
 \r
                public override bool CanSeek {\r
-                       get { return false; } //stream.CanSeek; }\r
+                       get { return stream.CanSeek; }\r
                }\r
 \r
                public override bool CanWrite {\r
index 4375afed1d8d388456fb0d62eb7e1dd5da8a6134..ebd31c913aea33b32f4ed020db0ae9677e38d93a 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Xml
                }
 
                public XmlTextReader (Stream input)
-                       : this (new StreamReader (input))
+                       : this (new XmlStreamReader (input))
                {
                }
 
@@ -68,12 +68,12 @@ namespace System.Xml
                }
 
                public XmlTextReader (Stream input, XmlNameTable nt)
-                       : this(new StreamReader (input), nt)
+                       : this(new XmlStreamReader (input), nt)
                {
                }
 
                public XmlTextReader (string url, Stream input)
-                       : this (url, new StreamReader (input))
+                       : this (url, new XmlStreamReader (input))
                {
                }
 
@@ -84,13 +84,12 @@ namespace System.Xml
 
                [MonoTODO("Non-filename-url must be supported. Waiting for WebClient")]
                public XmlTextReader (string url, XmlNameTable nt)
-                       // : this(url, new StreamReader ((Stream)new XmlUrlResolver ().GetEntity (new Uri (url), null, typeof(Stream))), nt)
-                       : this (url, new StreamReader (url), nt)
+                       : this (url, new XmlStreamReader (url), nt)
                {
                }
 
                public XmlTextReader (TextReader input, XmlNameTable nt)
-                       : this(String.Empty, input, nt)
+                       : this (String.Empty, input, nt)
                {
                }
 
@@ -100,7 +99,7 @@ namespace System.Xml
                }
 
                public XmlTextReader (string url, Stream input, XmlNameTable nt)
-                       : this (url, new StreamReader (input), nt)
+                       : this (url, new XmlStreamReader (input), nt)
                {
                }
 
@@ -599,7 +598,8 @@ namespace System.Xml
                                        endname = this.Name;
                                }
 
-                               xmlBuffer.Replace (currentTag.ToString (), "");
+                               if (currentTag.Length > 0)
+                                       xmlBuffer.Replace (currentTag.ToString (), "");
                                saveToXmlBuffer = false;
                                string InnerXml = xmlBuffer.ToString ();
                                xmlBuffer.Length = 0;