* 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
+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
\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
\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
\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
\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
\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
using System.Xml.XPath;
using System.Diagnostics;
using System.Collections;
+using Mono.Xml.Native;
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)
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:
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;
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;
}
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
\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
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;
//
// (C) 2002 Kral Ferch
//
+// [FIXME]
+// Document state should be considered.
+//
using System;
using System.Collections;
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;
using System.Net;
using System.IO;
+using Mono.Xml.Native;
namespace System.Xml
{