From 8d3ab987266dd55c69bcffa2a7ee3660a52af46d Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Sun, 10 Feb 2008 14:55:50 +0000 Subject: [PATCH] 2008-02-10 Atsushi Enomoto * 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 --- .../System.Xml.Linq/System.Xml.Linq/ChangeLog | 8 ++++++++ .../System.Xml.Linq/System.Xml.Linq/XElement.cs | 6 ++++-- .../System.Xml.Linq/XNodeWriter.cs | 8 ++++---- .../Test/System.Xml.Linq/ChangeLog | 6 ++++++ .../Test/System.Xml.Linq/ExtensionsTest.cs | 4 +++- .../Test/System.Xml.Linq/XNodeWriterTest.cs | 16 ++++++++++++++++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog b/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog index 2a9934fb70a..397e02957e3 100644 --- a/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog +++ b/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog @@ -1,3 +1,11 @@ +2008-02-10 Atsushi Enomoto + + * 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 * XNamespace.cs: implement. diff --git a/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs b/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs index 99e83cea87d..10b24dde644 100644 --- a/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs +++ b/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs @@ -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 (); diff --git a/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs b/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs index a8106cee92a..ed89b974aef 100644 --- a/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs +++ b/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs @@ -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; } diff --git a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog index b74dedc7ee8..f9d7f667ffd 100644 --- a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog +++ b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog @@ -1,3 +1,9 @@ +2008-02-10 Atsushi Enomoto + + * 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 * XNodeReaderTest.cs : test for bug #356522, the third case. diff --git a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs index f0f8d36fa55..dbdb6fbb08c 100644 --- a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs +++ b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs @@ -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 (""); - doc.Root.Nodes ().Remove (); + doc.Root.Nodes ().Remove (); Assert.IsNull (doc.Root.FirstNode, "#1"); } +*/ } } diff --git a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeWriterTest.cs b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeWriterTest.cs index d016d2333b5..027fee05f06 100644 --- a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeWriterTest.cs +++ b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeWriterTest.cs @@ -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 () { -- 2.25.1