DotNet6中的XMLSerializer以及Dotnet6中的XMLSerializer不编写Whiteves?
实际上,我在C#中尝试了此基本代码,该代码将数据集序列化为XML文档。
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();
}
这将创建使用适当的空格和.NET 5中的“ Demonet5.xml”文件。但是,当我尝试在.NET 6中运行相同的代码时 我没有得到白色的和凹痕,因此XML的内容是单行编写的。
稍后,当我尝试阅读该.xml文档时,我会面临问题。 有人可以帮助我吗?我希望我的XML内容具有适当的格式,该格式与适当的不同和空格相关。 使用.net6 创建的XML文件 我还使用了使用dotnet6创建的XML文档。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论