[Mono-bugs] [Bug 69350][Nor] New - WriteEndElement doesn't work after XmlTextWriter.WriteAttributes()
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 11 Nov 2004 05:46:07 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by jaak@zd.com.pl.
http://bugzilla.ximian.com/show_bug.cgi?id=69350
--- shadow/69350 2004-11-11 05:46:07.000000000 -0500
+++ shadow/69350.tmp.19961 2004-11-11 05:46:07.000000000 -0500
@@ -0,0 +1,94 @@
+Bug#: 69350
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jaak@zd.com.pl
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: WriteEndElement doesn't work after XmlTextWriter.WriteAttributes()
+
+I've noticed that WriteAttributes() causes WriteEndElement() to fail to
+close the XML element.
+
+Compile the following code snippet:
+
+--------------------
+using System;
+using System.Xml;
+using System.IO;
+
+class C1
+{
+ public static string ProcessXml(string s)
+ {
+ StringReader sr = new StringReader(s);
+ StringWriter sw = new StringWriter();
+ XmlTextReader xtr = new XmlTextReader(sr);
+ XmlTextWriter xtw = new XmlTextWriter(sw);
+
+ while (xtr.Read())
+ {
+ if (xtr.NodeType == XmlNodeType.Element)
+ {
+ xtw.WriteStartElement(xtr.LocalName);
+ xtw.WriteAttributes(xtr, false);
+ if (xtr.IsEmptyElement)
+ xtw.WriteEndElement();
+ }
+ else if (xtr.NodeType == XmlNodeType.EndElement)
+ {
+ xtw.WriteEndElement();
+ }
+ else if (xtr.NodeType == XmlNodeType.Whitespace)
+ {
+ xtw.WriteWhitespace(xtr.Value);
+ }
+ else
+ {
+ xtw.WriteNode(xtr, false);
+ }
+ }
+
+ return sw.ToString();
+ }
+
+ static void Main()
+ {
+ string input = "<test><a empty='true' /><b
+empty='false'><c /></b></test>";
+ string output = ProcessXml(input);
+
+ Console.WriteLine("IN: {0}", input);
+ Console.WriteLine("OUT: {0}", output);
+ }
+}
+-------------------------
+
+ProcessXml should basically replicate its XML input using a pair of
+XmlTextReader/XmlTextWriter, but on Mono it doesn't.
+
+On .NET 1.1 the output is:
+----------
+IN: <test><a empty='true' /><b empty='false'><c /></b></test>
+OUT: <test><a empty="true" /><b empty="false"><c /></b></test>
+----------
+
+On Mono/Linux - CVS HEAD:
+----------
+IN: <test><a empty='true' /><b empty='false'><c /></b></test>
+OUT: <test><a empty="true"><b empty="false"><c /></b></a>
+----------
+
+Notice that the <a> tag isn't closed in this case.
+
+After the WriteAttributes line is commented out the output lacks any
+attributes but the elements are properly balanced.