2008-02-10 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Sun, 10 Feb 2008 14:55:50 +0000 (14:55 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sun, 10 Feb 2008 14:55:50 +0000 (14:55 -0000)
* XElement.cs : .ctor(XName,object) was trying to set args as its
  content, not as its own fields.
* XNodeWriter.cs : check null ns and replace it with "".
  Now that IsEmpty is true, set IsEmpty as false explicitly
  when WriteFullEndElement() is called.

* ExtensionsTest.cs : disabled Remove() which does not compile now.
* XNodeWriterTest.cs : added test for Write[Full]EndElement() and
  XElement.IsEmpty.

svn path=/trunk/mcs/; revision=95377

mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeWriterTest.cs

index 2a9934fb70aff768d25d78421a6573ef601013c3..397e02957e3233cee4e5c5e2ab9b4d1e1adecfa3 100644 (file)
@@ -1,3 +1,11 @@
+2008-02-10  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XElement.cs : .ctor(XName,object) was trying to set args as its
+         content, not as its own fields.
+       * XNodeWriter.cs : check null ns and replace it with "".
+         Now that IsEmpty is true, set IsEmpty as false explicitly
+         when WriteFullEndElement() is called.
+
 2008-02-09  Miguel de Icaza  <miguel@novell.com>
 
        * XNamespace.cs: implement.
index 99e83cea87d4c96502e492ca46dab1764717960c..10b24dde644ea114fd24b70d0f4f0e0d6ae3c2dd 100644 (file)
@@ -47,11 +47,12 @@ namespace System.Xml.Linq
 
                XName name;
                XAttribute attr_first, attr_last;
-               bool explicit_is_empty;
+               bool explicit_is_empty = true;
 
                public XElement (XName name, object value)
                {
-                       SetElementValue (name, value);
+                       this.name = name;
+                       Add (value);
                }
 
                public XElement (XElement source)
@@ -398,6 +399,7 @@ namespace System.Xml.Linq
                                r.Read ();
                                e.ReadContentFrom (r);
                                r.ReadEndElement ();
+                               e.explicit_is_empty = false;
                        } else {
                                e.explicit_is_empty = true;
                                r.Read ();
index a8106cee92ac02c6975ffdf7f55bc7c7ffbca12b..ed89b974aefe23b0f97ceeb7daec068d71d81655 100644 (file)
@@ -223,7 +223,7 @@ namespace System.Xml.Linq
                {
                        CheckState ();
 
-                       XNamespace xns = XNamespace.Get (ns);
+                       XNamespace xns = XNamespace.Get (ns ?? String.Empty);
                        XElement el = new XElement (xns.GetName (name));
                        if (current == null) {
                                root.Add (el);
@@ -233,7 +233,7 @@ namespace System.Xml.Linq
                                state = XmlNodeType.Element;
                        }
 
-                       FillXmlns (el, prefix, xns);
+                       FillXmlns (el, prefix ?? String.Empty, xns);
 
                        current = el;
                }
@@ -257,8 +257,8 @@ namespace System.Xml.Linq
                                throw new InvalidOperationException ("Current state is not acceptable for endElement.");
 
                        XElement el = current as XElement;
-                       if (!forceFull && el != null && el.FirstNode == null)
-                               el.IsEmpty = true;
+                       if (forceFull)
+                               el.IsEmpty = false;
 
                        current = current.Parent;
                }
index b74dedc7ee83bbcec62b8658afcdba139dab4d87..f9d7f667ffdbf291c0117d18569a4ad1cbf95925 100644 (file)
@@ -1,3 +1,9 @@
+2008-02-10  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * ExtensionsTest.cs : disabled Remove() which does not compile now.
+       * XNodeWriterTest.cs : added test for Write[Full]EndElement() and
+         XElement.IsEmpty.
+
 2008-01-30  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XNodeReaderTest.cs : test for bug #356522, the third case.
index f0f8d36fa5570dd44c632db1041b27dd3ef453a9..dbdb6fbb08c5048fb67832af459dda62442f1a1c 100644 (file)
@@ -37,12 +37,14 @@ namespace MonoTests.System.Xml.Linq
        [TestFixture]
        public class ExtensionsTest
        {
+/* It does not compile probably due to bug #359733.
                [Test]
                public void Remove ()
                {
                        XDocument doc = XDocument.Parse ("<root><foo/><bar/><baz/></root>");
-                       doc.Root.Nodes ().Remove ();
+                       doc.Root.Nodes ().Remove<XNode> ();
                        Assert.IsNull (doc.Root.FirstNode, "#1");
                }
+*/
        }
 }
index d016d2333b57f0cdba1d6c93949a5657d3a3484b..027fee05f06f947e923bd5ef3189a3b2b4ab12ff 100644 (file)
@@ -38,6 +38,22 @@ namespace MonoTests.System.Xml.Linq
        [TestFixture]
        public class XNodeWriterTest
        {
+               [Test]
+               public void WriteEmptyElements ()
+               {
+                       var doc = new XDocument ();
+                       XmlWriter w = doc.CreateWriter ();
+                       w.WriteStartElement ("root");
+                       w.WriteStartElement ("foo");
+                       w.WriteEndElement ();
+                       w.WriteStartElement ("bar");
+                       w.WriteFullEndElement ();
+                       w.WriteEndElement ();
+                       w.Close ();
+                       Assert.IsTrue (((XElement) doc.Root.FirstNode).IsEmpty, "#1");
+                       Assert.IsFalse (((XElement) doc.Root.LastNode).IsEmpty, "#2");
+               }
+
                [Test]
                public void CreateWriter1 ()
                {