* 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
+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:
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)
Load (new XmlTextReader (txtReader));
}
+ [MonoTODO("XmlValidatingReader should be used.")]
public virtual void Load (XmlReader xmlReader)
{
// Reset our document
// like properties we have, etc.
RemoveAll ();
+ this.baseURI = xmlReader.BaseURI;
+
// create all contents with use of ReadNode()
do {
XmlNode n = ReadNode (xmlReader);
-//
-// 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
\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
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
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
}\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
}
public XmlTextReader (Stream input)
- : this (new StreamReader (input))
+ : this (new XmlStreamReader (input))
{
}
}
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))
{
}
[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)
{
}
}
public XmlTextReader (string url, Stream input, XmlNameTable nt)
- : this (url, new StreamReader (input), nt)
+ : this (url, new XmlStreamReader (input), nt)
{
}
endname = this.Name;
}
- xmlBuffer.Replace (currentTag.ToString (), "");
+ if (currentTag.Length > 0)
+ xmlBuffer.Replace (currentTag.ToString (), "");
saveToXmlBuffer = false;
string InnerXml = xmlBuffer.ToString ();
xmlBuffer.Length = 0;