'StreamWriter along with XmlSerializer in DotNet6 does not write WhiteSpaces?
Actually I tried this basic code in C# which serializes the DataSet into XML document.
static void Main(string[] args)
{
XmlSerializer ser = new XmlSerializer(typeof(DataSet));
// Creates a DataSet; adds a table, column, and ten rows.
DataSet ds = new DataSet("myDataSet");
DataTable t = new DataTable("table1");
DataColumn c = new DataColumn("thing");
t.Columns.Add(c);
ds.Tables.Add(t);
DataRow r;
for (int i = 0; i < 10; i++)
{
r = t.NewRow();
r[0] = "Thing " + i;
t.Rows.Add(r);
}
StreamWriter writer = new StreamWriter("DemoNet5.xml");
ser.Serialize(writer, ds);
writer.Close();
}
And this creates the "DemoNet5.xml" file with proper WhiteSpaces and Indentation in .NET 5. But When I try to run the same code in .NET 6 I am not getting the WhiteSapces and Indentation so that the contents of the xml are written in single line.
Later on when I try to read that .xml document I face issues. Is there someone who can help me with this ? I want my xml contents to be in proper format that is with proper indetation and WhiteSpaces. Xml file created using .NET6 I have also attached the XML document created using DotNet6.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|