Browse Source

*** empty log message ***

svn path=/trunk/mcs/; revision=8970
Atsushi Eno 23 years ago
parent
commit
50c3bfb8e5

+ 13 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,16 @@
+2002-11-14  Atsushi Enomoto <[email protected]>
+
+	* XmlDocument.cs : unified all constructors, added ConventionalParser,
+		implemented CloneNode() and CreateEntityReference(),
+	* XmlEntityReference.cs : set_Value, WriteContentTo, WriteTo
+		set BaseURI to MonoTODO
+	* XmlNode.cs : implemented PrependChild, modified ConstructDOM,
+		bugfix InsertAfter (incorrect prepending) and InsertBefore
+		(more than one DocumentElements hadn't caused errors)
+	* XmlTextReader.cs : unified all constructors,
+		added internal SetReaderContext(), SetReaderFragment()
+		bugfix (syntax check of PUBLIC / getting internal subset)
+
 2002-11-13  Atsushi Enomoto <[email protected]>
 
 	XmlAttribute.cs : set_InnerText, set_InnerXml, some check for set_Prefix

+ 78 - 63
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -7,9 +7,11 @@
 //   Jason Diamond <[email protected]>
 //   Miguel de Icaza ([email protected])
 //   Duncan Mak ([email protected])
+//   Atsushi Enomoto ([email protected])
 //
 // (C) 2001 Daniel Weber
-// (C) 2002 Kral Ferch, Jason Diamond, Miguel de Icaza, Duncan Mak
+// (C) 2002 Kral Ferch, Jason Diamond, Miguel de Icaza, Duncan Mak,
+//   Atsushi Enomoto
 //
 
 using System;
@@ -30,33 +32,30 @@ namespace System.Xml
 		string baseURI = String.Empty;
 		XmlImplementation implementation;
 		bool preserveWhitespace = true;	// Its true initial value is false.
+		WeakReference conventionalXmlTextReader;
 
 		#endregion
 
 		#region Constructors
 
-		public XmlDocument () : base (null)
+		public XmlDocument () : this (null, null)
 		{
-			implementation = new XmlImplementation();
-			nameTable = implementation.internalNameTable;
-			AddDefaultNameTableKeys();
 		}
 
-		protected internal XmlDocument (XmlImplementation imp) : base (null)
+		protected internal XmlDocument (XmlImplementation imp) : this (imp, null)
 		{
-			implementation = imp;
-			nameTable = imp.internalNameTable;
-			AddDefaultNameTableKeys();
 		}
 
-		public XmlDocument (XmlNameTable nt) : base (null)
+		public XmlDocument (XmlNameTable nt) : this (null, nt)
 		{
-			implementation = new XmlImplementation();
-			implementation.internalNameTable = nt;
-			nameTable = nt;
-			AddDefaultNameTableKeys();
 		}
 
+		XmlDocument (XmlImplementation impl, XmlNameTable nt) : base (null)
+		{
+			implementation = (impl != null) ? impl : new XmlImplementation ();
+			nameTable = (nt != null) ? nt : implementation.internalNameTable;
+			AddDefaultNameTableKeys ();
+		}
 		#endregion
 
 		#region Events
@@ -83,6 +82,19 @@ namespace System.Xml
 			}
 		}
 
+		// Used to read 'InnerXml's for its descendants at any place.
+		internal XmlTextReader ConventionalParser {
+			get {
+				if(conventionalXmlTextReader == null)
+					conventionalXmlTextReader = new WeakReference (null);
+				if(!conventionalXmlTextReader.IsAlive) {
+					XmlTextReader reader = new XmlTextReader ((TextReader)null);
+					conventionalXmlTextReader.Target = reader;
+				}
+				return (XmlTextReader)conventionalXmlTextReader.Target;
+			}
+		}
+
 		public XmlElement DocumentElement {
 			get {
 				XmlNode node = FirstChild;
@@ -117,7 +129,7 @@ namespace System.Xml
 				return base.InnerXml;
 			}
 			set {	// reason for overriding
-				this.LoadXml(value);
+				this.LoadXml (value);
 			}
 		}
 
@@ -169,17 +181,24 @@ namespace System.Xml
 
 		[MonoTODO]
 		public virtual XmlResolver XmlResolver {
-			set { throw new NotImplementedException(); }
+			set { throw new NotImplementedException (); }
 		}
 
 		#endregion
 
 		#region Methods
 
-		[MonoTODO]
+		[MonoTODO("Should BaseURI be cloned?")]
 		public override XmlNode CloneNode (bool deep)
 		{
-			throw new NotImplementedException ();
+			XmlDocument doc = implementation.CreateDocument ();
+			doc.PreserveWhitespace = PreserveWhitespace;	// required?
+			if(deep)
+			{
+				foreach(XmlNode n in ChildNodes)
+					doc.AppendChild (doc.ImportNode (n, deep));
+			}
+			return doc;
 		}
 
 		public XmlAttribute CreateAttribute (string name)
@@ -212,7 +231,7 @@ namespace System.Xml
 
 		public virtual XmlComment CreateComment (string data)
 		{
-			return new XmlComment(data, this);
+			return new XmlComment (data, this);
 		}
 
 		[MonoTODO]
@@ -223,7 +242,7 @@ namespace System.Xml
 
 		public virtual XmlDocumentFragment CreateDocumentFragment ()
 		{
-			return new XmlDocumentFragment(this);
+			return new XmlDocumentFragment (this);
 		}
 
 		public virtual XmlDocumentType CreateDocumentType (string name, string publicId,
@@ -260,10 +279,9 @@ namespace System.Xml
 			return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this);
 		}
 
-		[MonoTODO]
 		public virtual XmlEntityReference CreateEntityReference (string name)
 		{
-			throw new NotImplementedException ();
+			return new XmlEntityReference (name, this);
 		}
 
 		[MonoTODO]
@@ -433,44 +451,44 @@ namespace System.Xml
 				case XmlNodeType.Attribute:
 					{
 						XmlAttribute src_att = node as XmlAttribute;
-						XmlAttribute dst_att = this.CreateAttribute(src_att.Prefix, src_att.LocalName, src_att.NamespaceURI);
+						XmlAttribute dst_att = this.CreateAttribute (src_att.Prefix, src_att.LocalName, src_att.NamespaceURI);
 						dst_att.Value = src_att.Value;	// always explicitly specified (whether source is specified or not)
 						return dst_att;
 					}
 
 				case XmlNodeType.CDATA:
-					return this.CreateCDataSection(node.Value);
+					return this.CreateCDataSection (node.Value);
 
 				case XmlNodeType.Comment:
-					return this.CreateComment(node.Value);
+					return this.CreateComment (node.Value);
 
 				case XmlNodeType.Document:
-					throw new XmlException("Document cannot be imported.");
+					throw new XmlException ("Document cannot be imported.");
 
 				case XmlNodeType.DocumentFragment:
 					{
-						XmlDocumentFragment df = this.CreateDocumentFragment();
+						XmlDocumentFragment df = this.CreateDocumentFragment ();
 						if(deep)
 						{
 							foreach(XmlNode n in node.ChildNodes)
 							{
-								df.AppendChild(this.ImportNode(n, deep));
+								df.AppendChild (this.ImportNode (n, deep));
 							}
 						}
 						return df;
 					}
 
 				case XmlNodeType.DocumentType:
-					throw new XmlException("DocumentType cannot be imported.");
+					throw new XmlException ("DocumentType cannot be imported.");
 
 				case XmlNodeType.Element:
 					{
 						XmlElement src = (XmlElement)node;
-						XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI);
+						XmlElement dst = this.CreateElement (src.Prefix, src.LocalName, src.NamespaceURI);
 						foreach(XmlAttribute attr in src.Attributes)
 						{
 							if(attr.Specified)	// copies only specified attributes
-								dst.SetAttributeNode((XmlAttribute)this.ImportNode(attr, deep));
+								dst.SetAttributeNode ((XmlAttribute)this.ImportNode (attr, deep));
 							if(DocumentType != null)
 							{
 								// TODO: create default attribute values
@@ -479,7 +497,7 @@ namespace System.Xml
 						if(deep)
 						{
 							foreach(XmlNode n in src.ChildNodes)
-								dst.AppendChild(this.ImportNode(n, deep));
+								dst.AppendChild (this.ImportNode (n, deep));
 						}
 						return dst;
 					}
@@ -492,10 +510,8 @@ namespace System.Xml
 				case XmlNodeType.Entity:
 					throw new NotImplementedException ();	// TODO
 
-				// [2002.10.14] CreateEntityReference not implemented.
 				case XmlNodeType.EntityReference:
-					throw new NotImplementedException("ImportNode of EntityReference not implemented mainly because CreateEntityReference was implemented in the meantime.");
-//					return this.CreateEntityReference(node.Name);
+					return this.CreateEntityReference (node.Name);
 
 				case XmlNodeType.None:
 					throw new XmlException ("Illegal ImportNode call for NodeType.None");
@@ -505,20 +521,20 @@ namespace System.Xml
 
 				case XmlNodeType.ProcessingInstruction:
 					XmlProcessingInstruction pi = node as XmlProcessingInstruction;
-					return this.CreateProcessingInstruction(pi.Target, pi.Data);
+					return this.CreateProcessingInstruction (pi.Target, pi.Data);
 
 				case XmlNodeType.SignificantWhitespace:
-					return this.CreateSignificantWhitespace(node.Value);
+					return this.CreateSignificantWhitespace (node.Value);
 
 				case XmlNodeType.Text:
-					return this.CreateTextNode(node.Value);
+					return this.CreateTextNode (node.Value);
 
 				case XmlNodeType.Whitespace:
-					return this.CreateWhitespace(node.Value);
+					return this.CreateWhitespace (node.Value);
 
 				case XmlNodeType.XmlDeclaration:
 					XmlDeclaration srcDecl = node as XmlDeclaration;
-					return this.CreateXmlDeclaration(srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone);
+					return this.CreateXmlDeclaration (srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone);
 
 				default:
 					throw new NotImplementedException ();
@@ -631,19 +647,15 @@ namespace System.Xml
 			throw new NotImplementedException ();
 		}
 
-		[MonoTODO ("Verify what encoding is used by default;  Should use PreserveWhiteSpace")]
 		public virtual void Save(Stream outStream)
 		{
-			// To implementor: utf-8 is OK, at least for (ginga's) Japanese environment.
 			XmlTextWriter xmlWriter = new XmlTextWriter (outStream, Encoding.UTF8);
 			WriteContentTo (xmlWriter);
 			xmlWriter.Close ();
 		}
 
-		[MonoTODO ("Verify what encoding is used by default; Should use PreseveWhiteSpace")]
 		public virtual void Save (string filename)
 		{
-			// To implementor: utf-8 is OK, at least for (ginga's) Japanese environment.
 			XmlTextWriter xmlWriter = new XmlTextWriter (filename, Encoding.UTF8);
 			WriteContentTo (xmlWriter);
 			xmlWriter.Close ();
@@ -657,7 +669,6 @@ namespace System.Xml
 			xmlWriter.Flush ();
 		}
 
-		[MonoTODO ("Should preserve white space if PreserveWhisspace is set")]
 		public virtual void Save (XmlWriter xmlWriter)
 		{
 			//
@@ -669,32 +680,36 @@ namespace System.Xml
 
 		public override void WriteContentTo (XmlWriter w)
 		{
-			foreach(XmlNode childNode in ChildNodes)
-				childNode.WriteTo(w);
+			foreach(XmlNode childNode in ChildNodes) {
+				childNode.WriteTo (w);
+				if(!PreserveWhitespace) {
+					w.WriteRaw ("\n");
+				}
+			}
 		}
 
 		public override void WriteTo (XmlWriter w)
 		{
-			WriteContentTo(w);
+			WriteContentTo (w);
 		}
 
-		private void AddDefaultNameTableKeys()
+		private void AddDefaultNameTableKeys ()
 		{
 			// The following keys are default of MS .NET Framework
-			nameTable.Add("#text");
-			nameTable.Add("xml");
-			nameTable.Add("xmlns");
-			nameTable.Add("#entity");
-			nameTable.Add("#document-fragment");
-			nameTable.Add("#comment");
-			nameTable.Add("space");
-			nameTable.Add("id");
-			nameTable.Add("#whitespace");
-			nameTable.Add("http://www.w3.org/2000/xmlns/");
-			nameTable.Add("#cdata-section");
-			nameTable.Add("lang");
-			nameTable.Add("#document");
-			nameTable.Add("#significant-whitespace");
+			nameTable.Add ("#text");
+			nameTable.Add ("xml");
+			nameTable.Add ("xmlns");
+			nameTable.Add ("#entity");
+			nameTable.Add ("#document-fragment");
+			nameTable.Add ("#comment");
+			nameTable.Add ("space");
+			nameTable.Add ("id");
+			nameTable.Add ("#whitespace");
+			nameTable.Add ("http://www.w3.org/2000/xmlns/");
+			nameTable.Add ("#cdata-section");
+			nameTable.Add ("lang");
+			nameTable.Add ("#document");
+			nameTable.Add ("#significant-whitespace");
 		}
 		#endregion
 	}

+ 8 - 7
mcs/class/System.XML/System.Xml/XmlEntityReference.cs

@@ -24,7 +24,7 @@ namespace System.Xml
 		// Properties
 		[MonoTODO]
 		public override string BaseURI {
-			get { return null; }
+			get { throw new NotImplementedException (); }
 		}
 
 		public override bool IsReadOnly {
@@ -45,8 +45,9 @@ namespace System.Xml
 
 		public override string Value {
 			get { return null; } // always return null here.
-			[MonoTODO]
-			set { throw new NotImplementedException (); }
+			set {
+				throw new XmlException ("entity reference cannot be set value.");
+			}
 		}
 
 		// Methods
@@ -59,16 +60,16 @@ namespace System.Xml
 			return new XmlEntityReference ("", OwnerDocument);
 		}
 
-		[MonoTODO]
 		public override void WriteContentTo (XmlWriter w)
 		{
-			throw new NotImplementedException();
+			// nothing to write for this object.
 		}
 
-		[MonoTODO]
 		public override void WriteTo (XmlWriter w)
 		{
-			throw new NotImplementedException();
+			w.WriteRaw("&");
+			w.WriteName(Name);
+			w.WriteRaw(";");
 		}
 	}
 }

+ 138 - 162
mcs/class/System.XML/System.Xml/XmlNode.cs

@@ -35,19 +35,17 @@ namespace System.Xml
 
 		#region Properties
 
-		public virtual XmlAttributeCollection Attributes
-		{
+		public virtual XmlAttributeCollection Attributes {
 			get { return null; }
 		}
 
-		public virtual string BaseURI
-		{
+		public virtual string BaseURI {
 			get { return ParentNode.BaseURI; }
 		}
 
 		public virtual XmlNodeList ChildNodes {
 			get {
-				return new XmlNodeListChildren(this);
+				return new XmlNodeListChildren (this);
 			}
 		}
 
@@ -66,7 +64,7 @@ namespace System.Xml
 			get { return LastChild != null; }
 		}
 
-		[MonoTODO]
+		[MonoTODO("confirm whether this way is right for each not-overriden types.")]
 		public virtual string InnerText {
 			get {
 				StringBuilder builder = new StringBuilder ();
@@ -95,9 +93,9 @@ namespace System.Xml
 				StringWriter sw = new StringWriter ();
 				XmlTextWriter xtw = new XmlTextWriter (sw);
 
-				WriteContentTo(xtw);
+				WriteContentTo (xtw);
 
-				return sw.GetStringBuilder().ToString();
+				return sw.GetStringBuilder ().ToString ();
 			}
 
 			set { throw new NotImplementedException (); }
@@ -170,9 +168,9 @@ namespace System.Xml
 				StringWriter sw = new StringWriter ();
 				XmlTextWriter xtw = new XmlTextWriter (sw);
 
-				WriteTo(xtw);
+				WriteTo (xtw);
 
-				return sw.GetStringBuilder().ToString();
+				return sw.GetStringBuilder ().ToString ();
 			}
 		}
 
@@ -205,7 +203,7 @@ namespace System.Xml
 		public virtual XmlNode AppendChild (XmlNode newChild)
 		{
 			// I assume that AppendChild(n) equals to InsertAfter(n, this.LastChild) or InsertBefore(n, null)
-			return InsertBefore(newChild, null);
+			return InsertBefore (newChild, null);
 
 			// Below are formerly used logic.
 /*			XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
@@ -231,7 +229,7 @@ namespace System.Xml
 					for(int i=0; i<x; i++)
 					{
 						// When this logic became to remove children in order, then index will have never to increments.
-						XmlNode n = newChild.ChildNodes[0];
+						XmlNode n = newChild.ChildNodes [0];
 						this.AppendChild(n);	// recursively invokes events. (It is compatible with MS implementation.)
 					}
 				}
@@ -263,7 +261,7 @@ namespace System.Xml
 		public virtual XmlNode Clone ()
 		{
 			// By MS document, it is equivalent to CloneNode(true).
-			return this.CloneNode(true);
+			return this.CloneNode (true);
 		}
 
 		public abstract XmlNode CloneNode (bool deep);
@@ -271,28 +269,26 @@ namespace System.Xml
 		[MonoTODO]
 		public XPathNavigator CreateNavigator ()
 		{
-			return new XmlDocumentNavigator(this);
+			return new XmlDocumentNavigator (this);
 		}
 
 		public IEnumerator GetEnumerator ()
 		{
-			return new XmlNodeListChildren(this).GetEnumerator();
+			return new XmlNodeListChildren (this).GetEnumerator ();
 		}
 
-//		[MonoTODO]
+		[MonoTODO("performance problem.")]
 		public virtual string GetNamespaceOfPrefix (string prefix)
 		{
-			XmlNamespaceManager nsmgr = ConstructNamespaceManager();
-			return nsmgr.LookupNamespace(prefix);
-//			throw new NotImplementedException ();
+			XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+			return nsmgr.LookupNamespace (prefix);
 		}
 
-//		[MonoTODO]
+		[MonoTODO("performance problem.")]
 		public virtual string GetPrefixOfNamespace (string namespaceURI)
 		{
-			XmlNamespaceManager nsmgr = ConstructNamespaceManager();
-			return nsmgr.LookupPrefix(namespaceURI);
-//			throw new NotImplementedException ();
+			XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
+			return nsmgr.LookupPrefix (namespaceURI);
 		}
 
 		object ICloneable.Clone ()
@@ -305,83 +301,75 @@ namespace System.Xml
 			return GetEnumerator ();
 		}
 
-		[MonoTODO]
 		public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild)
 		{
 			// I assume that insertAfter(n1, n2) equals to InsertBefore(n1, n2.PreviousSibling).
 
 			// I took this way because rather than calling InsertAfter() from InsertBefore()
 			//   because current implementation of 'NextSibling' looks faster than 'PreviousSibling'.
-			XmlNode argNode = (refChild == null) ? null : refChild.NextSibling;
-			return InsertBefore(newChild, argNode);
+			XmlNode argNode = null;
+			if(refChild != null)
+				argNode = refChild.NextSibling;
+			else if(ChildNodes.Count > 0)
+				argNode = FirstChild;
+			return InsertBefore (newChild, argNode);
 		}
 
-		[MonoTODO]
 		public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild)
 		{
 			XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;
 
-			if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute || NodeType == XmlNodeType.DocumentFragment) 
-			{			
+			if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute || NodeType == XmlNodeType.DocumentFragment) {			
 				if (IsReadOnly)
 					throw new ArgumentException ("The specified node is readonly.");
 
 				if (newChild.OwnerDocument != ownerDoc)
 					throw new ArgumentException ("Can't append a node created by another document.");
 
-				if(refChild != null)
-				{
+				if(refChild != null) {
 					if(newChild.OwnerDocument != refChild.OwnerDocument)
 						throw new ArgumentException ("argument nodes are on the different documents.");
 
-					if(refChild == ownerDoc.DocumentElement && (newChild is XmlElement || newChild is XmlCharacterData || newChild is XmlEntityReference))
-						throw new XmlException("cannot insert this node to this position.");
 				}
+				if(this == ownerDoc && ownerDoc.DocumentElement != null && (newChild is XmlElement || newChild is XmlCharacterData || newChild is XmlEntityReference))
+					throw new XmlException ("cannot insert this node to this position.");
 				// checking validity finished. then appending...
 
 				ownerDoc.onNodeInserting (newChild, this);
 
 				if(newChild.ParentNode != null)
-					newChild.ParentNode.RemoveChild(newChild);
+					newChild.ParentNode.RemoveChild (newChild);
 
-				if(newChild.NodeType == XmlNodeType.DocumentFragment)
-				{
+				if(newChild.NodeType == XmlNodeType.DocumentFragment) {
 					int x = newChild.ChildNodes.Count;
-					for(int i=0; i<x; i++)
-					{
-						// When this logic became to remove children in order, then index will have never to increments.
-						XmlNode n = newChild.ChildNodes[0];
-						this.InsertBefore(n, refChild);	// recursively invokes events. (It is compatible with MS implementation.)
+					for(int i=0; i<x; i++) {
+						XmlNode n = newChild.ChildNodes [0];
+						this.InsertBefore (n, refChild);	// recursively invokes events. (It is compatible with MS implementation.)
 					}
 				}
-				else
-				{
+				else {
 					XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild;
 					XmlLinkedNode lastLinkedChild = LastLinkedChild;
 
 					newLinkedChild.parentNode = this;
 
-					if(refChild == null)
-					{
+					if(refChild == null) {
 						// append last, so:
 						// * set nextSibling of previous lastchild to newChild
 						// * set lastchild = newChild
 						// * set next of newChild to firstChild
-						if(LastLinkedChild != null)
-						{
+						if(LastLinkedChild != null) {
 							XmlLinkedNode formerFirst = FirstChild as XmlLinkedNode;
 							LastLinkedChild.NextLinkedSibling = newLinkedChild;
 							LastLinkedChild = newLinkedChild;
 							newLinkedChild.NextLinkedSibling = formerFirst;
 						}
-						else
-						{
+						else {
 							LastLinkedChild = newLinkedChild;
 							LastLinkedChild.NextLinkedSibling = newLinkedChild;	// FirstChild
 						}
 					}
-					else
-					{
+					else {
 						// append not last, so:
 						// * if newchild is first, then set next of lastchild is newChild.
 						//   otherwise, set next of previous sibling to newChild
@@ -398,7 +386,7 @@ namespace System.Xml
 				return newChild;
 			} 
 			else
-				throw new InvalidOperationException();
+				throw new InvalidOperationException ();
 		}
 
 		[MonoTODO]
@@ -407,10 +395,9 @@ namespace System.Xml
 			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public virtual XmlNode PrependChild (XmlNode newChild)
 		{
-			throw new NotImplementedException ();
+			return InsertAfter (newChild, null);
 		}
 
 		public virtual void RemoveAll ()
@@ -425,26 +412,25 @@ namespace System.Xml
 		public virtual XmlNode RemoveChild (XmlNode oldChild)
 		{
 			if(oldChild.ParentNode != this)
-				throw new XmlException("specified child is not child of this node.");
+				throw new XmlException ("specified child is not child of this node.");
 
 			OwnerDocument.onNodeRemoving (oldChild, oldChild.ParentNode);
 
-			if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute || NodeType == XmlNodeType.DocumentFragment) 
-			{
+			if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute || NodeType == XmlNodeType.DocumentFragment) {
 				if (IsReadOnly)
-					throw new ArgumentException();
+					throw new ArgumentException ();
 
-				if (Object.ReferenceEquals(LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(LastLinkedChild, oldChild))
+				if (Object.ReferenceEquals (LastLinkedChild, LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals (LastLinkedChild, oldChild))
 					LastLinkedChild = null;
 				else {
 					XmlLinkedNode oldLinkedChild = (XmlLinkedNode)oldChild;
 					XmlLinkedNode beforeLinkedChild = LastLinkedChild;
 					
-					while (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
+					while (!Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, LastLinkedChild) && !Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
 						beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
 
-					if (!Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
-						throw new ArgumentException();
+					if (!Object.ReferenceEquals (beforeLinkedChild.NextLinkedSibling, oldLinkedChild))
+						throw new ArgumentException ();
 
 					beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;
 					oldLinkedChild.NextLinkedSibling = null;
@@ -456,7 +442,7 @@ namespace System.Xml
 				return oldChild;
 			} 
 			else
-				throw new ArgumentException();
+				throw new ArgumentException ();
 		}
 
 		[MonoTODO]
@@ -520,96 +506,92 @@ namespace System.Xml
 		public abstract void WriteTo (XmlWriter w);
 
 		// It parses with XmlReader and then construct DOM of the parsed contents.
-		internal void ConstructDOM(XmlReader xmlReader, XmlNode currentNode)
+		internal void ConstructDOM (XmlReader xmlReader, XmlNode currentNode)
 		{
 			// I am not confident whether this method should be placed in this class or not...
 			// Please verify its validity and then erase this comment;-)
 			XmlNode newNode;
 			XmlDocument doc = currentNode is XmlDocument ? (XmlDocument)currentNode : currentNode.OwnerDocument;
 			// Below are 'almost' copied from XmlDocument.Load(XmlReader xmlReader)
-			while (xmlReader.Read ()) 
-			{
-				switch (xmlReader.NodeType) 
-				{
-					case XmlNodeType.CDATA:
-						newNode = doc.CreateCDataSection(xmlReader.Value);
-						currentNode.AppendChild (newNode);
-						break;
+			while (xmlReader.Read ()) {
+				switch (xmlReader.NodeType) {
+				case XmlNodeType.CDATA:
+					newNode = doc.CreateCDataSection (xmlReader.Value);
+					currentNode.AppendChild (newNode);
+					break;
 
-					case XmlNodeType.Comment:
-						newNode = doc.CreateComment (xmlReader.Value);
-						currentNode.AppendChild (newNode);
-						break;
-
-					case XmlNodeType.Element:
-						XmlElement element = doc.CreateElement (xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
-						currentNode.AppendChild (element);
-
-						// set the element's attributes.
-						while (xmlReader.MoveToNextAttribute ()) 
-						{
-							XmlAttribute attribute = doc.CreateAttribute (xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
-							attribute.Value = xmlReader.Value;
-							element.SetAttributeNode (attribute);
-						}
+				case XmlNodeType.Comment:
+					newNode = doc.CreateComment (xmlReader.Value);
+					currentNode.AppendChild (newNode);
+					break;
 
-						xmlReader.MoveToElement ();
+				case XmlNodeType.Element:
+					XmlElement element = doc.CreateElement (xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
+					element.IsEmpty = xmlReader.IsEmptyElement;
+					currentNode.AppendChild (element);
+
+					// set the element's attributes.
+					while (xmlReader.MoveToNextAttribute ()) {
+						XmlAttribute attribute = doc.CreateAttribute (xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI);
+						attribute.Value = xmlReader.Value;
+						element.SetAttributeNode (attribute);
+					}
 
-						// if this element isn't empty, push it onto our "stack".
-						if (!xmlReader.IsEmptyElement)
-							currentNode = element;
+					xmlReader.MoveToElement ();
 
-						break;
+					// if this element isn't empty, push it onto our "stack".
+					if (!xmlReader.IsEmptyElement)
+						currentNode = element;
 
-					case XmlNodeType.EndElement:
-						currentNode = currentNode.ParentNode;
-						break;
+					break;
 
-					case XmlNodeType.ProcessingInstruction:
-						newNode = doc.CreateProcessingInstruction (xmlReader.Name, xmlReader.Value);
-						currentNode.AppendChild (newNode);
-						break;
+				case XmlNodeType.EndElement:
+					currentNode = currentNode.ParentNode;
+					break;
+
+				case XmlNodeType.ProcessingInstruction:
+					newNode = doc.CreateProcessingInstruction (xmlReader.Name, xmlReader.Value);
+					currentNode.AppendChild (newNode);
+					break;
+
+				case XmlNodeType.Text:
+					newNode = doc.CreateTextNode (xmlReader.Value);
+					currentNode.AppendChild (newNode);
+					break;
+
+				case XmlNodeType.XmlDeclaration:
+					// empty strings are dummy, then gives over setting value contents to setter.
+					newNode = doc.CreateXmlDeclaration ("1.0" , String.Empty, String.Empty);
+					((XmlDeclaration)newNode).Value = xmlReader.Value;
+					this.AppendChild (newNode);
+					break;
+
+				case XmlNodeType.DocumentType:
+					XmlTextReader xmlTextReader = xmlReader as XmlTextReader;
+					if(xmlTextReader != null) {
+						XmlDocumentType dtdNode = doc.CreateDocumentType (xmlTextReader.Name, xmlTextReader.publicId, xmlTextReader.systemId, xmlTextReader.Value);
+						this.AppendChild (dtdNode);
+					}
+					else
+						throw new XmlException ("construction of DocumentType node from this XmlReader is not supported.");
+					break;
+
+				case XmlNodeType.EntityReference:
+					newNode = doc.CreateEntityReference (xmlReader.Name);
+					currentNode.AppendChild (newNode);
+					break;
 
-					case XmlNodeType.Text:
-						newNode = doc.CreateTextNode (xmlReader.Value);
+				case XmlNodeType.SignificantWhitespace:
+					newNode = doc.CreateSignificantWhitespace (xmlReader.Value);
+					currentNode.AppendChild (newNode);
+					break;
+
+				case XmlNodeType.Whitespace:
+					if(doc.PreserveWhitespace) {
+						newNode = doc.CreateWhitespace (xmlReader.Value);
 						currentNode.AppendChild (newNode);
-						break;
-
-					case XmlNodeType.XmlDeclaration:
-						// empty strings are dummy, then gives over setting value contents to setter.
-						newNode = doc.CreateXmlDeclaration("1.0" , String.Empty, String.Empty);
-						((XmlDeclaration)newNode).Value = xmlReader.Value;
-						this.AppendChild(newNode);
-						break;
-
-					case XmlNodeType.DocumentType:
-						XmlTextReader xmlTextReader = xmlReader as XmlTextReader;
-						if(xmlTextReader != null)
-						{
-							XmlDocumentType dtdNode = doc.CreateDocumentType(xmlTextReader.Name, xmlTextReader.publicId, xmlTextReader.systemId, xmlTextReader.Value);
-							this.AppendChild(dtdNode);
-						}
-						else
-							throw new XmlException("construction of DocumentType node from this XmlReader is not supported.");
-						break;
-
-					case XmlNodeType.EntityReference:
-						newNode = doc.CreateEntityReference(xmlReader.Name);
-						currentNode.AppendChild(newNode);
-						break;
-
-					case XmlNodeType.SignificantWhitespace:
-						newNode = doc.CreateSignificantWhitespace(xmlReader.Value);
-						currentNode.AppendChild(newNode);
-						break;
-
-					case XmlNodeType.Whitespace:
-						if(doc.PreserveWhitespace)
-						{
-							newNode = doc.CreateWhitespace(xmlReader.Value);
-							currentNode.AppendChild(newNode);
-						}
-						break;
+					}
+					break;
 				}
 			}
 		}
@@ -617,34 +599,28 @@ namespace System.Xml
 		// It parses this and all the ancestor elements,
 		// find 'xmlns' declarations, stores and then return them.
 		// TODO: tests
-		internal XmlNamespaceManager ConstructNamespaceManager()
+		internal XmlNamespaceManager ConstructNamespaceManager ()
 		{
 			XmlDocument doc = this is XmlDocument ? (XmlDocument)this : this.OwnerDocument;
-			XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
+			XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
 			XmlElement el = null;
-			switch(this.NodeType)
-			{
-				case XmlNodeType.Attribute:
-					el = ((XmlAttribute)this).OwnerElement;
-					break;
-				case XmlNodeType.Element:
-					el = this as XmlElement;
-					break;
-				default:
-					el = this.ParentNode as XmlElement;
-					break;
+			switch(this.NodeType) {
+			case XmlNodeType.Attribute:
+				el = ((XmlAttribute)this).OwnerElement;
+				break;
+			case XmlNodeType.Element:
+				el = this as XmlElement;
+				break;
+			default:
+				el = this.ParentNode as XmlElement;
+				break;
 			}
 
-			while(el != null)
-			{			
-				foreach(XmlAttribute attr in el.Attributes)
-				{
-					if(attr.Prefix == "xmlns" || (attr.Name == "xmlns" && attr.Prefix == String.Empty))
-					{
-						if(nsmgr.LookupNamespace(attr.LocalName) == null )
-						{
-							nsmgr.AddNamespace(attr.LocalName, attr.Value);
-						}
+			while(el != null) {
+				foreach(XmlAttribute attr in el.Attributes) {
+					if(attr.Prefix == "xmlns" || (attr.Name == "xmlns" && attr.Prefix == String.Empty)) {
+						if(nsmgr.LookupNamespace (attr.LocalName) == null )
+							nsmgr.AddNamespace (attr.LocalName, attr.Value);
 					}
 				}
 				// When reached to document, then it will set null value :)

+ 131 - 146
mcs/class/System.XML/System.Xml/XmlTextReader.cs

@@ -47,115 +47,80 @@ namespace System.Xml
 		{
 		}
 
-		[MonoTODO]
 		public XmlTextReader (Stream input)
+			: this (new StreamReader (input))
 		{
-			// We can share some code in the constructors (at least for this one and next 2)
-			XmlNameTable nt = new NameTable ();
-			XmlNamespaceManager nsMgr = new XmlNamespaceManager (nt);
-			parserContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
-			Init ();
-			reader = new StreamReader (input);
-			can_seek = input.CanSeek;
 		}
 
-		[MonoTODO]
 		public XmlTextReader (string url)
+			: this(url, new NameTable ())
 		{
-			XmlNameTable nt = new NameTable ();
-			XmlNamespaceManager nsMgr = new XmlNamespaceManager (nt);
-			parserContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
-			Init ();
-			// StreamReader does not support url, only filepath;-)
-			reader = new StreamReader(url);
-			can_seek = reader.Peek () != -1;
 		}
 
-		[MonoTODO]
 		public XmlTextReader (TextReader input)
+			: this (input, new NameTable ())
 		{
-			XmlNameTable nt = new NameTable ();
-			XmlNamespaceManager nsMgr = new XmlNamespaceManager (nt);
-			parserContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
-			Init ();
-			reader = input;
-			can_seek = input.Peek () != -1;
 		}
 
-		[MonoTODO]
 		protected XmlTextReader (XmlNameTable nt)
+			: this (String.Empty, null, XmlNodeType.None, null)
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public XmlTextReader (Stream input, XmlNameTable nt)
+			: this(new StreamReader (input), nt)
  		{
-			XmlNamespaceManager nsMgr = new XmlNamespaceManager (nt);
-			parserContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
-			Init ();
-			reader = new StreamReader (input);
-			can_seek = input.CanSeek;
 		}
 
-		[MonoTODO]
 		public XmlTextReader (string url, Stream input)
+			: this (url, new StreamReader (input))
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public XmlTextReader (string url, TextReader input)
+			: this (url, input, new NameTable ())
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
+		[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)
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public XmlTextReader (TextReader input, XmlNameTable nt)
+			: this(String.Empty, input, nt)
 		{
-			XmlNamespaceManager nsMgr = new XmlNamespaceManager (nt);
-			parserContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
-			Init ();
-			reader = input;
-			can_seek = input.Peek () != -1;
 		}
 
-		[MonoTODO]
 		public XmlTextReader (Stream xmlFragment, XmlNodeType fragType, XmlParserContext context)
+			: this (String.Empty, new StreamReader (xmlFragment), fragType, context)
 		{
-			parserContext = context;
-			reader = new StreamReader(xmlFragment);
-			can_seek = xmlFragment.CanSeek;
-			Init();
-//			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public XmlTextReader (string url, Stream input, XmlNameTable nt)
+			: this (url, new StreamReader (input), nt)
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
 		public XmlTextReader (string url, TextReader input, XmlNameTable nt)
+			: this (url, input, XmlNodeType.Document, new XmlParserContext (nt, new XmlNamespaceManager (nt), null, XmlSpace.None))
 		{
-			throw new NotImplementedException ();
 		}
 
-		[MonoTODO]
+		[MonoTODO("TODO as same as private XmlTextReader(TextReader, XmlNodeType, XmlParserContext)")]
 		public XmlTextReader (string xmlFragment, XmlNodeType fragType, XmlParserContext context)
+			: this (String.Empty, new StringReader (xmlFragment), fragType, context)
 		{
-			//Waiting for Validating reader for fragType rules.
-			parserContext = context;
-			Init ();
-			reader = new StringReader(xmlFragment);
-			can_seek = true;
+		}
+
+		// TODO still remains as described at head of this file,
+		// but it might not be TODO of the constructors...
+		XmlTextReader (string url, TextReader fragment, XmlNodeType fragType, XmlParserContext context)
+		{
+			this.SetReaderContext(url, context);
+			this.SetReaderFragment(fragment, fragType);
 		}
 
 		#endregion
@@ -535,7 +500,7 @@ namespace System.Xml
 					endname = this.Name;
 				}
 
-				xmlBuffer.Replace(currentTag.ToString (), "");
+				xmlBuffer.Replace (currentTag.ToString (), "");
 				saveToXmlBuffer = false;
 				string InnerXml = xmlBuffer.ToString ();
 				xmlBuffer.Length = 0;
@@ -547,10 +512,10 @@ namespace System.Xml
 		public override string ReadOuterXml ()
 		{
 			if (NodeType == XmlNodeType.Attribute) {
-				return Name+"=\""+Value+"\"";
+				return Name + "=\"" + Value + "\"";
 			} else {
    				saveToXmlBuffer = true;
-				xmlBuffer.Append(currentTag.ToString ());
+				xmlBuffer.Append (currentTag.ToString ());
 				string startname = this.Name;
 				string endname = string.Empty;
 				readState = ReadState.Interactive;
@@ -643,6 +608,38 @@ namespace System.Xml
 		internal string publicId;
 		internal string systemId;
 
+		internal void SetReaderContext (string url, XmlParserContext context)
+		{
+			parserContext = context;
+			parserContext.BaseURI = url;
+			Init ();
+		}
+
+		internal void SetReaderFragment(TextReader fragment, XmlNodeType fragType)
+		{
+			this.reader = fragment;
+			can_seek = fragment != null && fragment.Peek () != -1;
+/*	for future use
+			switch(fragType)
+			{
+			case XmlNodeType.Attribute:	// attribute content
+				parserContext.InputState = XmlParserInputState.AttributeValue;
+				break;
+			case XmlNodeType.DocumentFragment:	// element content
+				parserContext.InputState = XmlParserInputState.Content;
+				break;
+			case XmlNodeType.Element:	// one element
+				parserContext.InputState = XmlParserInputState.StartTag;
+				break;
+			case XmlNodeType.Document:	// document content
+				parserContext.InputState = XmlParserInputState.Start;
+				break;
+			default:
+				throw new InvalidOperationException("setting this xml node type not allowed.");
+			}
+*/
+		}
+
 		private void Init ()
 		{
 			readState = ReadState.Initial;
@@ -1201,6 +1198,13 @@ namespace System.Xml
 				AppendValueChar ((char)ch);
 			}
 
+/* for future use
+			if(target == "xml") && parserContext.InputState != XmlParserInputState.Start)
+				throw new XmlException("Xml declaration is not allowed here.");
+			else {
+				parserContext.InputState = XmlParserInputState.DTD; //for future use
+			}
+*/
 			SetProperties (
 				target == "xml" ?
 				XmlNodeType.XmlDeclaration :
@@ -1308,69 +1312,49 @@ namespace System.Xml
 			string doctypeName = null;
 			string publicId = String.Empty;
 			string systemId = String.Empty;
-			string internalSubset = String.Empty;
 
-			SkipWhitespace();
-			doctypeName = ReadName();
-			SkipWhitespace();
+			SkipWhitespace ();
+			doctypeName = ReadName ();
+			SkipWhitespace ();
 			xmlBuffer.Length = 0;
-			switch(PeekChar())
+			switch(PeekChar ())
 			{
 			case 'S':
-				systemId = ReadSystemLiteral();
+				systemId = ReadSystemLiteral (true);
 				break;
 			case 'P':
-/*
-				Expect("PUBLIC");
-				SkipWhitespace();
-				int quoteChar = ReadChar();
-				int c = 0;
-				while(c != quoteChar)
-				{
-					c = ReadChar();
-					if(c < 0)
-						throw new XmlException("Unexpected end of stream in ExternalID.");
-					if(c != quoteChar)
-					{
-						if(XmlChar.IsPubidChar(c)) xmlBuffer.Append((char)c);
-						else
-							throw new XmlException("character '" + (char)c + "' not allowed for PUBLIC ID");
-					}
-				}
-				publicId = xmlBuffer.ToString();
-				*/
-				publicId = ReadPubidLiteral();
-				SkipWhitespace();
-				systemId = ReadSystemLiteral();
+				publicId = ReadPubidLiteral ();
+				SkipWhitespace ();
+				systemId = ReadSystemLiteral (false);
 				break;
 			}
-			SkipWhitespace();
+			SkipWhitespace ();
 
 
-			if(PeekChar() == '[')
+			if(PeekChar () == '[')
 			{
 				// read markupdecl etc. or end of decl
-				ReadChar();
+				ReadChar ();
+				xmlBuffer.Length = 0;
 				saveToXmlBuffer = true;
-				do
-				{
-					ReadDTDInternalSubset();
+				do {
+					ReadDTDInternalSubset ();
 				} while(nodeType != XmlNodeType.None);
-				xmlBuffer.Remove(xmlBuffer.Length -1, 1);	// cut off ']'
+				xmlBuffer.Remove (xmlBuffer.Length - 1, 1);	// cut off ']'
 				saveToXmlBuffer = false;
 			}
 			// end of DOCTYPE decl.
-			SkipWhitespace();
-			Expect('>');
+			SkipWhitespace ();
+			Expect ('>');
 
-			internalSubset = xmlBuffer.ToString();
+			parserContext.InternalSubset = xmlBuffer.ToString ();
 
 			// set properties for <!DOCTYPE> node
 			SetProperties (
 				XmlNodeType.DocumentType, // nodeType
 				doctypeName, // name
 				false, // isEmptyElement
-				internalSubset, // value
+				parserContext.InternalSubset, // value
 				true // clearAttributes
 				);
 		}
@@ -1383,124 +1367,125 @@ namespace System.Xml
 		//	 (if None then ']' was found.)
 		private void ReadDTDInternalSubset()
 		{
-			SkipWhitespace();
-			switch(ReadChar())
+			SkipWhitespace ();
+			switch(ReadChar ())
 			{
 			case ']':
 				nodeType = XmlNodeType.None;
 				break;
 			case '%':
-				string peName = ReadName();
-				Expect(';');
+				string peName = ReadName ();
+				Expect (';');
 				nodeType = XmlNodeType.EntityReference;	// It's chating a bit;-)
 				break;
 			case '<':
-				switch(ReadChar())
+				switch(ReadChar ())
 				{
 				case '?':
-					ReadProcessingInstruction();
+					ReadProcessingInstruction ();
 					break;
 				case '!':
-					switch(ReadChar())
+					switch(ReadChar ())
 					{
 					case '-':
-						Expect('-');
-						ReadComment();
+						Expect ('-');
+						ReadComment ();
 						break;
 					case 'E':
-						switch(ReadChar())
+						switch(ReadChar ())
 						{
 						case 'N':
-							Expect("TITY");
-							ReadEntityDecl();
+							Expect ("TITY");
+							ReadEntityDecl ();
 							break;
 						case 'L':
-							Expect("EMENT");
-							ReadElementDecl();
+							Expect ("EMENT");
+							ReadElementDecl ();
 							break;
 						default:
-							throw new XmlException("Syntax Error after '<!E' (ELEMENT or ENTITY must be found)");
+							throw new XmlException ("Syntax Error after '<!E' (ELEMENT or ENTITY must be found)");
 						}
 						break;
 					case 'A':
-						Expect("TTLIST");
-						ReadAttListDecl();
+						Expect ("TTLIST");
+						ReadAttListDecl ();
 						break;
 					case 'N':
-						Expect("OTATION");
-						ReadNotationDecl();
+						Expect ("OTATION");
+						ReadNotationDecl ();
 						break;
 					default:
-						throw new XmlException("Syntax Error after '<!' characters.");
+						throw new XmlException ("Syntax Error after '<!' characters.");
 					}
 					break;
 				default:
-					throw new XmlException("Syntax Error after '<' character.");
+					throw new XmlException ("Syntax Error after '<' character.");
 				}
 				break;
 			default:
-				throw new XmlException("Syntax Error inside doctypedecl markup.");
+				throw new XmlException ("Syntax Error inside doctypedecl markup.");
 			}
 		}
 
 		// The reader is positioned on the head of the name.
 		private void ReadElementDecl()
 		{
-			while(ReadChar() != '>');
+			while(ReadChar () != '>');
 		}
 
 		private void ReadEntityDecl()
 		{
-			while(ReadChar() != '>');
+			while(ReadChar () != '>');
 		}
 
 		private void ReadAttListDecl()
 		{
-			while(ReadChar() != '>');
+			while(ReadChar () != '>');
 		}
 
 		private void ReadNotationDecl()
 		{
-			while(ReadChar() != '>');
+			while(ReadChar () != '>');
 		}
 		
 		// The reader is positioned on the first 'S' of "SYSTEM".
-		private string ReadSystemLiteral ()
+		private string ReadSystemLiteral (bool expectSYSTEM)
 		{
-			Expect("SYSTEM");
-			SkipWhitespace();
-			int quoteChar = ReadChar();	// apos or quot
+			if(expectSYSTEM)
+				Expect ("SYSTEM");
+			SkipWhitespace ();
+			int quoteChar = ReadChar ();	// apos or quot
 			xmlBuffer.Length = 0;
 			saveToXmlBuffer = true;
 			int c = 0;
-			while(c != quoteChar)
-			{
-				c = ReadChar();
-				if(c < 0) throw new XmlException("Unexpected end of stream in ExternalID.");
+			while(c != quoteChar) {
+				c = ReadChar ();
+				if(c < 0) throw new XmlException ("Unexpected end of stream in ExternalID.");
 			}
 			saveToXmlBuffer = false;
-			xmlBuffer.Remove(xmlBuffer.Length-1, 1);	// cut quoteChar
-			return xmlBuffer.ToString();
+			xmlBuffer.Remove (xmlBuffer.Length-1, 1);	// cut quoteChar
+			return xmlBuffer.ToString ();
 		}
 
 		private string ReadPubidLiteral()
 		{
-			Expect("PUBLIC");
-			SkipWhitespace();
-			int quoteChar = ReadChar();
+			Expect ("PUBLIC");
+			SkipWhitespace ();
+			int quoteChar = ReadChar ();
 			xmlBuffer.Length = 0;
 			saveToXmlBuffer = true;
 			int c = 0;
 			while(c != quoteChar)
 			{
-				c = ReadChar();
-				if(c < 0) throw new XmlException("Unexpected end of stream in ExternalID.");
-				if(c != quoteChar && !XmlChar.IsPubidChar(c))
+				c = ReadChar ();
+				if(c < 0) throw new XmlException ("Unexpected end of stream in ExternalID.");
+				if(c != quoteChar && !XmlChar.IsPubidChar (c))
 					throw new XmlException("character '" + (char)c + "' not allowed for PUBLIC ID");
 			}
-			xmlBuffer.Remove(xmlBuffer.Length-1, 1);	// cut quoteChar
+			ReadChar();	// skips quoteChar
+			xmlBuffer.Remove (xmlBuffer.Length-1, 1);	// cut quoteChar
 			saveToXmlBuffer = false;
-			return xmlBuffer.ToString();
+			return xmlBuffer.ToString ();
 		}
 
 		// The reader is positioned on the first character
@@ -1542,7 +1527,7 @@ namespace System.Xml
 		{
 			int len = expected.Length;
 			for(int i=0; i< len; i++)
-				Expect(expected[i]);
+				Expect (expected[i]);
 		}
 
 		// Does not consume the first non-whitespace character.

+ 1 - 0
mcs/class/System.XML/Test/AllTests.cs

@@ -30,6 +30,7 @@ namespace MonoTests.System.Xml
 				suite.AddTest (new TestSuite (typeof (XmlDocumentFragmentTests)));
 				suite.AddTest (new TestSuite (typeof (NameTableTests)));
 				suite.AddTest (new TestSuite (typeof (XmlElementTests)));
+				suite.AddTest (new TestSuite (typeof (XmlEntityReferenceTests)));
 				suite.AddTest (new TestSuite (typeof (XmlNodeTests)));
 				suite.AddTest (new TestSuite (typeof (XmlNodeListTests)));
 				suite.AddTest (new TestSuite (typeof (XmlCharacterDataTests)));

+ 10 - 0
mcs/class/System.XML/Test/ChangeLog

@@ -1,3 +1,13 @@
+2002-11-13  Atsushi Enomoto <[email protected]>
+
+	* AllTests.cs : added XmlEntityReferenceTests
+	* XmlDocumentTests.cs : TestCloneNode, TestDocumentWithDoctypeDecl
+	* XmlDocumentFragmentTests.cs : TestSetInnerXml
+	* XmlEntityReferenceTests.cs : created
+	* XmlTextWriterTests.cs : TestWriteAttributes() bugfix (reusing ctx)
+	* XmlNodeTests.cs : bugfix TestInsertAfter(when refChild = null),
+		added TestPrependChild
+
 2002-11-13  Atsushi Enomoto <[email protected]>
 
 	* XmlAttributeTests.cs : TestSetInnerAndOuterXml

+ 46 - 35
mcs/class/System.XML/Test/XmlDocumentFragmentTests.cs

@@ -18,65 +18,76 @@ namespace MonoTests.System.Xml
 		XmlDocument document;
 		XmlDocumentFragment fragment;
 		
-		public XmlDocumentFragmentTests(string name)
+		public XmlDocumentFragmentTests (string name)
 			: base (name)
 		{
 		}
 
-		protected override void SetUp()
+		protected override void SetUp ()
 		{
 		}
 
-		public void TestConstructor()
+		public void TestConstructor ()
 		{
-			XmlDocument d = new XmlDocument();
-			XmlDocumentFragment df = d.CreateDocumentFragment();
-			AssertEquals("#Constructor.NodeName", "#document-fragment", df.Name);
-			AssertEquals("#Constructor.NodeType", XmlNodeType.DocumentFragment, df.NodeType);
+			XmlDocument d = new XmlDocument ();
+			XmlDocumentFragment df = d.CreateDocumentFragment ();
+			AssertEquals ("#Constructor.NodeName", "#document-fragment", df.Name);
+			AssertEquals ("#Constructor.NodeType", XmlNodeType.DocumentFragment, df.NodeType);
 		}
 
-		public void TestAppendChildToFragment()
+		public void TestAppendChildToFragment ()
 		{
-			document = new XmlDocument();
-			fragment = document.CreateDocumentFragment();
-			document.LoadXml("<html><head></head><body></body></html>");
-			XmlElement el = document.CreateElement("p");
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			document.LoadXml ("<html><head></head><body></body></html>");
+			XmlElement el = document.CreateElement ("p");
 			el.InnerXml = "Test Paragraph";
 
 			// appending element to fragment
-			fragment.AppendChild(el);
-			AssertNotNull("#AppendChildToFragment.Element", fragment.FirstChild);
-			AssertNotNull("#AppendChildToFragment.Element.Children", fragment.FirstChild.FirstChild);
-			AssertEquals("#AppendChildToFragment.Element.Child.Text", "Test Paragraph", fragment.FirstChild.FirstChild.Value);
+			fragment.AppendChild (el);
+			AssertNotNull ("#AppendChildToFragment.Element", fragment.FirstChild);
+			AssertNotNull ("#AppendChildToFragment.Element.Children", fragment.FirstChild.FirstChild);
+			AssertEquals ("#AppendChildToFragment.Element.Child.Text", "Test Paragraph", fragment.FirstChild.FirstChild.Value);
 		}
 
-		public void TestAppendFragmentToElement()
+		public void TestAppendFragmentToElement ()
 		{
-			document = new XmlDocument();
-			fragment = document.CreateDocumentFragment();
-			document.LoadXml("<html><head></head><body></body></html>");
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			document.LoadXml ("<html><head></head><body></body></html>");
 			XmlElement body = document.DocumentElement.LastChild as XmlElement;
-			fragment.AppendChild(document.CreateElement("p"));
-			fragment.AppendChild(document.CreateElement("div"));
+			fragment.AppendChild (document.CreateElement ("p"));
+			fragment.AppendChild (document.CreateElement ("div"));
 
 			// appending fragment to element
-			body.AppendChild(fragment);
-			AssertNotNull("#AppendFragmentToElement.Exist", body.FirstChild);
-			AssertEquals("#AppendFragmentToElement.ChildIsElement", XmlNodeType.Element, body.FirstChild.NodeType);
-			AssertEquals("#AppendFragmentToElement.FirstChild", "p", body.FirstChild.Name);
-			AssertEquals("#AppendFragmentToElement.LastChild", "div", body.LastChild.Name);
+			body.AppendChild (fragment);
+			AssertNotNull ("#AppendFragmentToElement.Exist", body.FirstChild);
+			AssertEquals ("#AppendFragmentToElement.ChildIsElement", XmlNodeType.Element, body.FirstChild.NodeType);
+			AssertEquals ("#AppendFragmentToElement.FirstChild", "p", body.FirstChild.Name);
+			AssertEquals ("#AppendFragmentToElement.LastChild", "div", body.LastChild.Name);
 		}
 
-		public void TestGetInnerXml()
+		public void TestGetInnerXml ()
 		{
-			// this will be of TestWriteTo/TestWriteContentTo
+			// this will be also tests of TestWriteTo()/TestWriteContentTo()
 
-			document = new XmlDocument();
-			fragment = document.CreateDocumentFragment();
-			fragment.AppendChild(document.CreateElement("foo"));
-			fragment.AppendChild(document.CreateElement("bar"));
-			fragment.AppendChild(document.CreateElement("baz"));
-			AssertEquals("#Simple", "<foo /><bar /><baz />", fragment.InnerXml);
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			fragment.AppendChild (document.CreateElement ("foo"));
+			fragment.AppendChild (document.CreateElement ("bar"));
+			fragment.AppendChild (document.CreateElement ("baz"));
+			AssertEquals ("#Simple", "<foo /><bar /><baz />", fragment.InnerXml);
+		}
+
+		public void TestSetInnerXml ()
+		{
+			document = new XmlDocument ();
+			fragment = document.CreateDocumentFragment ();
+			fragment.InnerXml = "<foo /><bar><child /></bar><baz />";
+			AssertEquals ("foo", fragment.FirstChild.Name);
+			AssertEquals ("bar", fragment.FirstChild.NextSibling.Name);
+			AssertEquals ("child", fragment.FirstChild.NextSibling.FirstChild.Name);
+			AssertEquals ("baz", fragment.LastChild.Name);
 		}
 	}
 }

+ 24 - 22
mcs/class/System.XML/Test/XmlDocumentTests.cs

@@ -811,39 +811,41 @@ namespace MonoTests.System.Xml
 			AssertNotNull(doc.DocumentElement);
 		}
 
-		public void TestDocumentWithDoctypeDecl()
+		public void TestDocumentWithDoctypeDecl ()
 		{
-			XmlDocument doc = new XmlDocument();
+			XmlDocument doc = new XmlDocument ();
 			try {
-				doc.LoadXml("<!DOCTYPE test><root />");
-			} catch(XmlException) {
-				Fail("#DoctypeDecl.OnlyName");
+				doc.LoadXml ("<!DOCTYPE test><root />");
+			} catch (XmlException) {
+				Fail ("#DoctypeDecl.OnlyName");
 			}
 			try 
 			{
-				doc.LoadXml("<!DOCTYPE test SYSTEM 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
-			} 
-			catch(XmlException) 
-			{
+				doc.LoadXml ("<!DOCTYPE test SYSTEM 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
+			} catch (XmlException) {
 				Fail("#DoctypeDecl.System");
 			}
-			try 
-			{
-				doc.LoadXml("<!DOCTYPE test PUBLIC '-//test' SYSTEM 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
-			} 
-			catch(XmlException) 
-			{
-				Fail("#DoctypeDecl.Public");
+			try {
+				doc.LoadXml ("<!DOCTYPE test PUBLIC '-//test' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><root />");
+			} catch (XmlException) {
+				Fail ("#DoctypeDecl.Public");
 			}
 			// Should this be commented out?
-//			try 
-//			{
-//				doc.LoadXml("<!DOCTYPE test [<!ELEMENT foo >]><root />");
-//			} 
-//			catch(XmlException) 
-//			{
+//			try {
+//				doc.LoadXml ("<!DOCTYPE test [<!ELEMENT foo >]><root />");
+//			} catch (XmlException) {
 //				Fail("#DoctypeDecl.ElementDecl");
 //			}
 		}
+
+		public void TestCloneNode ()
+		{
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml ("<foo><bar /><baz hoge='fuga'>TEST Text</baz></foo>");
+			XmlDocument doc2 = (XmlDocument)doc.CloneNode (false);
+			AssertEquals ("ShallowCopy", 0, doc2.ChildNodes.Count);
+			doc2 = (XmlDocument)doc.CloneNode (true);
+			AssertEquals ("DeepCopy", "foo", doc2.DocumentElement.Name);
+		}
 	}
 }

+ 35 - 0
mcs/class/System.XML/Test/XmlEntityReferenceTests.cs

@@ -0,0 +1,35 @@
+//
+// System.Xml.XmlEntityReference.cs
+//
+// Author:
+//   Atsushi Enomoto <[email protected]>
+//
+// (C) 2002 Atsushi Enomoto
+//
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+	public class XmlEntityReferenceTests : TestCase
+	{
+		public XmlEntityReferenceTests () : base ("MonoTests.System.Xml.XmlEntityReferenceTests testsuite") {}
+		public XmlEntityReferenceTests (string name) : base (name) {}
+
+		protected override void SetUp ()
+		{
+		}
+
+		public void TestWriteTo ()
+		{
+			XmlDocument doc = new XmlDocument();
+			doc.LoadXml("<root/>");
+			XmlEntityReference er = doc.CreateEntityReference("foo");
+			doc.DocumentElement.AppendChild(er);
+			AssertEquals ("Name", "foo", er.Name);
+			AssertEquals ("WriteTo", "<root>&foo;</root>", doc.DocumentElement.OuterXml);
+		}
+	}
+}

+ 11 - 2
mcs/class/System.XML/Test/XmlNodeTests.cs

@@ -134,12 +134,21 @@ namespace MonoTests.System.Xml
 			AssertEquals("InsertAfter.Next", "good_child", docelem.LastChild.PreviousSibling.Name);
 			try 
 			{
-				document.InsertBefore(document.CreateElement("BAD_MAN"), docelem);
-				Fail("#InsertBefore.BadPositionButNoError.1");
+				document.InsertAfter(document.CreateElement("BAD_MAN"), docelem);
+				Fail("#InsertAfter.BadPositionButNoError.1");
 			}
 			catch(XmlException) {}
 		}
 
+		public void TestPrependChild()
+		{
+			document = new XmlDocument();
+			document.LoadXml("<root><sub1 /><sub2 /></root>");
+			XmlElement docelem = document.DocumentElement;
+			docelem.PrependChild(document.CreateElement("prepender"));
+			AssertEquals("PrependChild", "prepender", docelem.FirstChild.Name);
+		}
+
 		public void saveTestRemoveAll ()
 		{
 			// TODO:  put this test back in when AttributeCollection.RemoveAll() is implemented.

+ 1 - 0
mcs/class/System.XML/Test/XmlTextWriterTests.cs

@@ -924,6 +924,7 @@ namespace MonoTests.System.Xml
 			AssertEquals("#WriteAttributes.XmlDecl.1", "version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"", sw.ToString().Trim());
 
 			sb.Remove(0, sb.Length);	// init
+			ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", XmlSpace.Default);
 			xtr = new XmlTextReader("<?xml version='1.0'		 standalone='no'?><root a1='A' b2='B' c3='C'><foo><bar /></foo></root>", XmlNodeType.Document, ctx);
 			xtr.Read();	// read XMLDecl
 			wr.WriteAttributes(xtr, false);