The following two cases behave differently in Net 2.0. The
Case_Create_Str ingWriter throws an exception while the Case_XmlTextWri ter
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_XmlTextWri ter();
Case_Create_Str ingWriter();
}
static void Case_Create_Str ingWriter()
{
try
{
System.IO.Strin gWriter sw = new System.IO.Strin gWriter();
XmlWriter xw = XmlWriter.Creat e(sw);
WriteXml(xw);
System.Console. WriteLine("xml Create-StringWriter=" + sw.ToString());
}
catch (Exception e)
{
System.Console. WriteLine("xml Create-StringWriter=ex ception = " +
e.Message);
}
}
static void Case_XmlTextWri ter()
{
System.IO.Strin gWriter sw = new System.IO.Strin gWriter();
XmlTextWriter xw = new XmlTextWriter(s w);
WriteXml(xw);
System.Console. WriteLine("xml XmlTextWriter=" + sw.ToString());
}
static void WriteXml(XmlWri ter xw)
{
xw.WriteStartEl ement("document ");
xw.WriteAttribu teString("xsi:n il", "true");
xw.WriteEndElem ent();
xw.Flush();
xw.Close();
}
}
}