2003-02-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlElement.cs
index b00c7128ed06548f56319cc71188ef2c051d0b55..6b6fd2838b8e06b11f48d2df56ea53c6d1970595 100644 (file)
@@ -66,12 +66,17 @@ namespace System.Xml
                                return base.InnerText;
                        }
                        set {
-                               foreach(XmlNode n in ChildNodes)
-                               {
-                                       this.RemoveChild(n);
+                               // Why its behavior (of MS FCL) is different from InnerXml...?
+                               if (FirstChild != null && FirstChild.NodeType == XmlNodeType.Text)
+                                       FirstChild.Value = value;
+                               else {
+                                       if(FirstChild != null) {
+                                               foreach (XmlNode n in ChildNodes)
+                                                       this.RemoveChild (n);
+                                       }
+                                       // creates new Text node
+                                       AppendChild(OwnerDocument.CreateTextNode(value));
                                }
-                               // creates new Text node
-                               AppendChild(OwnerDocument.CreateTextNode(value));
                        }
                }
 
@@ -357,15 +362,12 @@ namespace System.Xml
                {
                        w.WriteStartElement(Prefix, LocalName, NamespaceURI);
 
-                       // write namespace declarations(if not exist)
-                       if(Prefix != null && w.LookupPrefix (Prefix) != NamespaceURI)
-                               w.WriteAttributeString ("xmlns", Prefix, "http://www.w3.org/2000/xmlns/", NamespaceURI);
-
                        foreach(XmlNode attributeNode in Attributes)
-                       {
                                attributeNode.WriteTo(w);
-                               // write namespace declarations(if not exist)
-                               if(attributeNode.Prefix != null && attributeNode.Prefix != "" &&\r
+
+                       // write namespace declarations(if not exist)
+                       foreach(XmlNode attributeNode in Attributes) {
+                               if(attributeNode.Prefix != null && attributeNode.Prefix != String.Empty &&\r
                                        w.LookupPrefix(attributeNode.Prefix) != attributeNode.NamespaceURI &&\r
                                        attributeNode.Prefix != "xmlns")\r
                                        w.WriteAttributeString("xmlns", attributeNode.Prefix, "http://www.w3.org/2000/xmlns/", attributeNode.NamespaceURI);