The following two cases behave differently in Net 2.0. The
Case_Create_StringWriter throws an exception while the Case_XmlTextWriter
does not.
Is there a problem with this code?
Or is this a known problem?
--------------------------------------------------------------------------
using System;
using System.Xml;
using System.Text;
namespace TestXmlNil2005
{
class Program
{
static void Main(string[] args)
{
Case_XmlTextWriter();
Case_Create_StringWriter();
}
static void Case_Create_StringWriter()
{
try
{
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlWriter xw = XmlWriter.Create(sw);
WriteXml(xw);
System.Console.WriteLine("xml Create-StringWriter=" + sw.ToString());
}
catch (Exception e)
{
System.Console.WriteLine("xml Create-StringWriter=exception = " +
e.Message);
}
}
static void Case_XmlTextWriter()
{
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
WriteXml(xw);
System.Console.WriteLine("xml XmlTextWriter=" + sw.ToString());
}
static void WriteXml(XmlWriter xw)
{
xw.WriteStartElement("document");
xw.WriteAttributeString("xsi:nil", "true");
xw.WriteEndElement();
xw.Flush();
xw.Close();
}
}
}