فهرست منبع

2009-11-11 Atsushi Enomoto <[email protected]>

	* XmlDocument.cs, XmlElement.cs, XmlAttribute.cs,
	  XmlAttributeCollection.cs :
	  when CreateElement() and/or CreateAttribute() are overriden,
	  use overriden method. Otherwise, use internal optimal ones.
	  Fixed bug #549839.


svn path=/trunk/mcs/; revision=145920
Atsushi Eno 16 سال پیش
والد
کامیت
2b68d146fa

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

@@ -1,3 +1,11 @@
+2009-11-11  Atsushi Enomoto  <[email protected]>
+
+	* XmlDocument.cs, XmlElement.cs, XmlAttribute.cs,
+	  XmlAttributeCollection.cs :
+	  when CreateElement() and/or CreateAttribute() are overriden,
+	  use overriden method. Otherwise, use internal optimal ones.
+	  Fixed bug #549839.
+
 2009-11-11  Atsushi Enomoto  <[email protected]>
 
 	* XmlNodeReaderImpl.cs : when the reader is at attribute value,

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

@@ -299,8 +299,7 @@ namespace System.Xml
 
 		public override XmlNode CloneNode (bool deep)
 		{
-			XmlNode node = new XmlAttribute (name.Prefix, name.LocalName, name.NS,
-							 OwnerDocument, true, false);
+			XmlNode node = OwnerDocument.CreateAttribute (name.Prefix, name.LocalName, name.NS, true, false);
 			if (deep) {
 				for (XmlNode n = FirstChild; n != null; n = n.NextSibling)
 					node.AppendChild (n.CloneNode (deep), false);

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

@@ -213,7 +213,7 @@ namespace System.Xml
 			DTDAttributeDefinition def = retAttr.GetAttributeDefinition ();
 			if (def != null && def.DefaultValue != null) {
 				XmlAttribute attr = ownerDocument.CreateAttribute (
-					retAttr.Prefix, retAttr.LocalName, retAttr.NamespaceURI);
+					retAttr.Prefix, retAttr.LocalName, retAttr.NamespaceURI, true, false);
 				attr.Value = def.DefaultValue;
 				attr.SetDefault ();
 				this.SetNamedItem (attr);

+ 32 - 8
mcs/class/System.XML/System.Xml/XmlDocument.cs

@@ -52,6 +52,8 @@ namespace System.Xml
 	public class XmlDocument : XmlNode, IHasXmlChildNode
 	{
 		#region Fields
+		static readonly Type [] optimal_create_types = new Type [] {typeof (string), typeof (string), typeof (string)};
+		bool optimal_create_element, optimal_create_attribute;
 
 		XmlNameTable nameTable;
 		string baseURI = String.Empty;
@@ -100,6 +102,10 @@ namespace System.Xml
 			nameCache = new XmlNameEntryCache (nameTable);
 			AddDefaultNameTableKeys ();
 			resolver = new XmlUrlResolver ();
+			
+			Type type = GetType ();
+			optimal_create_element = type.GetMethod ("CreateElement", optimal_create_types).DeclaringType == type;
+			optimal_create_attribute = type.GetMethod ("CreateAttribute", optimal_create_types).DeclaringType == type;
 		}
 		#endregion
 
@@ -327,15 +333,18 @@ namespace System.Xml
 
 		public virtual XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI)
 		{
-			return CreateAttribute (prefix, localName, namespaceURI, false, true);
+			if ((localName == null) || (localName == String.Empty))
+				throw new ArgumentException ("The attribute local name cannot be empty.");
+
+			return new XmlAttribute (prefix, localName, namespaceURI, this, false, true);
 		}
 
 		internal XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI, bool atomizedNames, bool checkNamespace)
 		{
-			if ((localName == null) || (localName == String.Empty))
-				throw new ArgumentException ("The attribute local name cannot be empty.");
-
-			return new XmlAttribute (prefix, localName, namespaceURI, this, atomizedNames, checkNamespace);
+			if (optimal_create_attribute)
+				return new XmlAttribute (prefix, localName, namespaceURI, this, atomizedNames, checkNamespace);
+			else
+				return CreateAttribute (prefix, localName, namespaceURI);
 		}
 
 		public virtual XmlCDataSection CreateCDataSection (string data)
@@ -394,14 +403,29 @@ namespace System.Xml
 			string localName,
 			string namespaceURI)
 		{
-			if ((localName == null) || (localName == String.Empty))
-				throw new ArgumentException ("The local name for elements or attributes cannot be null or an empty string.");
 			// LAMESPEC: MS.NET has a weird behavior that they can Load() from XmlTextReader 
 			// whose Namespaces = false, but their CreateElement() never allows qualified name.
 			// I leave it as it is.
 			return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this, false);
 		}
 
+		internal XmlElement CreateElement (
+			string prefix,
+			string localName,
+			string namespaceURI,
+			bool nameAtomized)
+		{
+			if ((localName == null) || (localName == String.Empty))
+				throw new ArgumentException ("The local name for elements or attributes cannot be null or an empty string.");
+			if (optimal_create_element)
+				// LAMESPEC: MS.NET has a weird behavior that they can Load() from XmlTextReader 
+				// whose Namespaces = false, but their CreateElement() never allows qualified name.
+				// I leave it as it is.
+				return new XmlElement (prefix != null ? prefix : String.Empty, localName, namespaceURI != null ? namespaceURI : String.Empty, this, nameAtomized);
+			else
+				return CreateElement (prefix, localName, namespaceURI);
+		}
+
 		public virtual XmlEntityReference CreateEntityReference (string name)
 		{
 			return new XmlEntityReference (name, this);
@@ -880,7 +904,7 @@ namespace System.Xml
 				break;
 
 			case XmlNodeType.Element:
-				XmlElement element = CreateElement (reader.Prefix, reader.LocalName, reader.NamespaceURI);
+				XmlElement element = CreateElement (reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.NameTable == this.NameTable);
 #if NET_2_0
 				if (reader.SchemaInfo != null)
 					SchemaInfo = new XmlSchemaInfo (reader.SchemaInfo);

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

@@ -250,8 +250,8 @@ namespace System.Xml
 		
 		public override XmlNode CloneNode (bool deep)
 		{
-			XmlElement node = new XmlElement (
-				name.Prefix, name.LocalName, name.NS, OwnerDocument, true);
+			XmlElement node = OwnerDocument.CreateElement (
+				name.Prefix, name.LocalName, name.NS, true);
 
 			for (int i = 0; i < Attributes.Count; i++)
 				node.SetAttributeNode ((XmlAttribute)