2009-11-11 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 11 Nov 2009 04:27:02 +0000 (04:27 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 11 Nov 2009 04:27:02 +0000 (04:27 -0000)
* 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

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlAttribute.cs
mcs/class/System.XML/System.Xml/XmlAttributeCollection.cs
mcs/class/System.XML/System.Xml/XmlDocument.cs
mcs/class/System.XML/System.Xml/XmlElement.cs

index ec9ea3c11a21aa16f40b2a31f7bd5a1aece11647..7ddc7ef87d2f3ac057075b839fc7ce157fcdfd65 100644 (file)
@@ -1,3 +1,11 @@
+2009-11-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * 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  <atsushi@ximian.com>
 
        * XmlNodeReaderImpl.cs : when the reader is at attribute value,
index 43cfb3e8a5153f2e3441defa4eaa036f1aa26c44..4a79204ceb21e4af69c04d09a884db942f36a71a 100644 (file)
@@ -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);
index e450d2d540b0539482516eff5c45ab5ee2965774..580aedb6e3f06f5e3fad5b616459c7514ecb0265 100644 (file)
@@ -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);
index fa7157ebca2a905e95338a0c9119b7b15ab5405d..c10c9ac79a6683bb345f1880f7e5359ec54208dd 100644 (file)
@@ -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);
index 8fe9e64136876ec5adbfb79524caa47668e2d943..9fc0ce9d74d81b55c801ba6d53615e753053cda5 100644 (file)
@@ -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)