Prechádzať zdrojové kódy

2003-05-18 Atsushi Enomoto <[email protected]>

	* XmlTextWriter.cs : patch by Jonathan Hogg. Flush() does not close
	  any open attributes or elements. WriteWhitespace() checks state and
	  closes start tag.  Fixed WriteStringInternal() to replace CR/LF chars
	  when it is called inside attribute value.
	* XmlException.cs : added .NET 1.1 .ctor.
	* added XmlSecureResolver.cs (only stubbing).
	* XmlAttribute.cs : set_InnerXml() should remove children.
	* XmlAttribute.cs,
	  XmlElement.cs,
	  XmlDocumentFragment.cs,
	  XmlDocument.cs : removed XmlTextReader reuse (It was buggy stuff).
	* XmlNode.cs : RemoveAll() should also remove all attributes.
	* XmlTextRader.cs : .ctor() for attribute value reader should add
	  quotations at initialization, since it requires quote chars.
	* XmlWriter.cs : WriteAttributeString() more correct xmlns check.

svn path=/trunk/mcs/; revision=14655
Atsushi Eno 22 rokov pred
rodič
commit
c80e582449

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

@@ -1,3 +1,21 @@
+2003-05-18  Atsushi Enomoto <[email protected]>
+
+	* XmlTextWriter.cs : patch by Jonathan Hogg. Flush() does not close
+	  any open attributes or elements. WriteWhitespace() checks state and
+	  closes start tag.  Fixed WriteStringInternal() to replace CR/LF chars
+	  when it is called inside attribute value.
+	* XmlException.cs : added .NET 1.1 .ctor.
+	* added XmlSecureResolver.cs (only stubbing).
+	* XmlAttribute.cs : set_InnerXml() should remove children.
+	* XmlAttribute.cs,
+	  XmlElement.cs,
+	  XmlDocumentFragment.cs,
+	  XmlDocument.cs : removed XmlTextReader reuse (It was buggy stuff).
+	* XmlNode.cs : RemoveAll() should also remove all attributes.
+	* XmlTextRader.cs : .ctor() for attribute value reader should add
+	  quotations at initialization, since it requires quote chars.
+	* XmlWriter.cs : WriteAttributeString() more correct xmlns check.
+
 2003-05-16  Atsushi Enomoto <[email protected]>
 
 	* changed XPathNodeType modifier to internal *protected* override.

+ 2 - 3
mcs/class/System.XML/System.Xml/XmlAttribute.cs

@@ -94,11 +94,10 @@ namespace System.Xml
 			}
 
 			set {
+				RemoveAll ();
 				XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
 				XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr, XmlLang, this.XmlSpace);
-				XmlTextReader xtr = OwnerDocument.ReusableReader;
-				xtr.Initialize (BaseURI, ctx, new System.IO.StringReader ("'" + value.Replace ("'", "&apos;") + "'"), XmlNodeType.Attribute);
-
+				XmlTextReader xtr = new XmlTextReader (value, XmlNodeType.Attribute, ctx);
 				OwnerDocument.ReadAttributeNodeValue (xtr, this);
 			}
 		}

+ 1 - 15
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -34,7 +34,6 @@ namespace System.Xml
 		string baseURI = String.Empty;
 		XmlImplementation implementation;
 		bool preserveWhitespace = false;
-		WeakReference reusableXmlTextReader;
 		XmlResolver resolver;
 
 		#endregion
@@ -85,19 +84,6 @@ namespace System.Xml
 			}
 		}
 
-		// Used to read 'InnerXml's for its descendants at any place.
-		internal XmlTextReader ReusableReader {
-			get {
-				if(reusableXmlTextReader == null)
-					reusableXmlTextReader = new WeakReference (null);
-				if(!reusableXmlTextReader.IsAlive) {
-					XmlTextReader reader = new XmlTextReader ((TextReader)null);
-					reusableXmlTextReader.Target = reader;
-				}
-				return (XmlTextReader)reusableXmlTextReader.Target;
-			}
-		}
-
 		public XmlElement DocumentElement {
 			get {
 				XmlNode node = FirstChild;
@@ -683,7 +669,7 @@ namespace System.Xml
 					attribute.AppendChild (CreateEntityReference (reader.Name));
 				// FIXME: else if(NodeType == EndEntity) -- reset BaseURI and so on -- ;
 				else
-					// (IMHO) Children of Attribute is likely restricted to Text and EntityReference.
+					// Children of Attribute is restricted to CharacterData and EntityReference (Comment is not allowed).
 					attribute.AppendChild (CreateTextNode (reader.Value));
 			}
 		}

+ 2 - 2
mcs/class/System.XML/System.Xml/XmlDocumentFragment.cs

@@ -29,6 +29,7 @@ namespace System.Xml
 		}
 		
 		#endregion
+
 		#region Properties
 
 		[MonoTODO("Setter is as incomplete as that of XmlElement.InnerXml")]
@@ -44,8 +45,7 @@ namespace System.Xml
 				XmlNameTable nt = this.OwnerDocument.NameTable;
 				XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
 				XmlParserContext ctx = new XmlParserContext (nt, nsmgr, XmlLang, this.XmlSpace);
-				XmlTextReader xmlReader = OwnerDocument.ReusableReader;
-				xmlReader.Initialize (String.Empty, ctx, new StringReader (value), XmlNodeType.Element);
+				XmlTextReader xmlReader = new XmlTextReader (value, XmlNodeType.Element, ctx);
 
 				do {
 					XmlNode n = OwnerDocument.ReadNode (xmlReader);

+ 1 - 2
mcs/class/System.XML/System.Xml/XmlElement.cs

@@ -92,8 +92,7 @@ namespace System.Xml
 				XmlNameTable nt = this.OwnerDocument.NameTable;
 				XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
 				XmlParserContext ctx = new XmlParserContext (nt, nsmgr, XmlLang, this.XmlSpace);
-				XmlTextReader xmlReader = OwnerDocument.ReusableReader;
-				xmlReader.Initialize (String.Empty, ctx, new StringReader (value), XmlNodeType.Element);
+				XmlTextReader xmlReader = new XmlTextReader (value, XmlNodeType.Element, ctx);
 
 				do {
 					XmlNode n = OwnerDocument.ReadNode (xmlReader);

+ 17 - 1
mcs/class/System.XML/System.Xml/XmlException.cs

@@ -24,6 +24,13 @@ namespace System.Xml
 
 		#region Constructors
 
+#if USE_VERSION_1_0
+#else
+		public XmlException () 
+			: base ()
+		{
+		}
+#endif
 		public XmlException (string message, Exception innerException) 
 			: base (message, innerException)
 		{
@@ -36,7 +43,11 @@ namespace System.Xml
 			this.linePosition = info.GetInt32 ("linePosition");
 		}
 
+#if USE_VERSION_1_0
 		internal XmlException (string message)
+#else
+		public XmlException (string message)
+#endif
 			: base (message)
 		{
 		}
@@ -49,7 +60,12 @@ namespace System.Xml
 			}
 		}
 		
-		internal XmlException (string message, int lineNumber, int linePosition) : base (message)
+#if USE_VERSION_1_0
+		internal XmlException (string message, int lineNumber, int linePosition)
+#else
+		public XmlException (string message, int lineNumber, int linePosition)
+#endif
+			: base (message)
 		{
 			this.lineNumber = lineNumber;
 			this.linePosition = linePosition;

+ 2 - 0
mcs/class/System.XML/System.Xml/XmlNode.cs

@@ -397,6 +397,8 @@ namespace System.Xml
 
 		public virtual void RemoveAll ()
 		{
+			if (Attributes != null)
+				Attributes.RemoveAll ();
 			XmlNode next = null;
 			for (XmlNode node = FirstChild; node != null; node = next) {
 				next = node.NextSibling;

+ 94 - 0
mcs/class/System.XML/System.Xml/XmlSecureResolver.cs

@@ -0,0 +1,94 @@
+#if USE_VERSION_1_0
+#endif
+#if USE_VERSION_1_1
+//
+// System.Xml.XmlSecureResolver.cs
+//
+// Author: Atsushi Enomoto ([email protected])
+//
+// (C) 2003 Atsushi Enomoto
+//
+using System;
+using System.Net;
+using System.Security;
+using System.Security.Policy;
+
+namespace System.Xml
+{
+	public class XmlSecureResolver : XmlResolver
+	{
+
+#region Static Members
+
+		[MonoTODO]
+		public static Evidence CreateEvidenceForUrl (string securityUrl)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public static new bool Equals (object objA, object objB)
+		{
+			throw new NotImplementedException ();
+		}
+#endregion
+
+#region .ctor and Finalizer
+
+		[MonoTODO]
+		public XmlSecureResolver (
+			XmlResolver resolver, Evidence evidence)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public XmlSecureResolver (
+			XmlResolver resolver, PermissionSet permissionSet)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public XmlSecureResolver (
+			XmlResolver resolver, string securityUrl)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~XmlSecureResolver ()
+		{
+			// What is expected here, not in Dispose() ?
+		}
+#endregion
+
+#region Property
+
+		[MonoTODO]
+		public override ICredentials Credentials {
+			set { throw new NotImplementedException (); }
+		}
+
+#endregion
+
+#region Methods
+
+		[MonoTODO]
+		public override object GetEntity (
+			Uri absoluteUri, string role, Type ofObjectToReturn)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override Uri ResolveUri ( Uri baseUri, string relativeUri)
+		{
+			throw new NotImplementedException ();
+		}
+
+#endregion
+
+	}
+}
+#endif

+ 1 - 1
mcs/class/System.XML/System.Xml/XmlTextReader.cs

@@ -711,7 +711,7 @@ namespace System.Xml
 
 			switch (fragType) {
 			case XmlNodeType.Attribute:
-				value = fragment.ReadToEnd ();
+				value = String.Format ("{0}{1}{0}", "'", fragment.ReadToEnd ().Replace ("'", "&apos;"));
 				break;
 			case XmlNodeType.Element:
 				allowMultipleRoot = true;

+ 14 - 1
mcs/class/System.XML/System.Xml/XmlTextWriter.cs

@@ -282,7 +282,7 @@ namespace System.Xml
 
 		public override void Flush ()
 		{
-                        CloseOpenAttributeAndElements ();
+//			CloseOpenAttributeAndElements ();
 			w.Flush ();
 		}
 
@@ -663,6 +663,11 @@ namespace System.Xml
 			WriteStringInternal (text, true);
 		}
 
+		private string NormalizeAttributeString (string value)
+		{
+			return value.Replace ("\r", "&#xD;").Replace ("\n", "&#xA;");
+		}
+
 		private void WriteStringInternal (string text, bool entitize)
 		{
 			if (text == null)
@@ -683,6 +688,7 @@ namespace System.Xml
 							text = text.Replace ("\"", "&quot;");
 						else
 							text = text.Replace ("'", "&apos;");
+						text = NormalizeAttributeString (text);
 					}
 				}
 
@@ -727,6 +733,13 @@ namespace System.Xml
 			foreach (char c in ws) {
 				if ((c != ' ') && (c != '\t') && (c != '\r') && (c != '\n'))
 					throw new ArgumentException ();
+			}
+
+			CheckState ();
+
+			if (!openAttribute) {
+				IndentingOverriden = true;
+				CloseStartElement ();
 			}
 
 			w.Write (ws);

+ 3 - 8
mcs/class/System.XML/System.Xml/XmlWriter.cs

@@ -79,19 +79,14 @@ namespace System.Xml
 
 		public void WriteAttributeString (string prefix, string localName, string ns, string value)
 		{
-			if ((prefix == "xmlns") || (localName == "xmlns"))
+			if ((prefix == "xmlns") || (prefix == "" && localName == "xmlns"))
 			  {
 				ns = value;
 				
 				if (prefix == "xmlns" && namespaceManager.HasNamespace (localName))
 				  	return;
-				
-				/* Users need to be able to re-declare the default namespace for subnodes
-				else if (localName == "xmlns" && namespaceManager.HasNamespace (String.Empty))
-				  	return;
-				*/
-			  }
-			
+			}
+
 			WriteStartAttribute (prefix, localName, ns);
 			WriteString (value);
 			WriteEndAttribute ();