C# 是否可以更改将数据集保存为xml时使用的缩进样式

C# 是否可以更改将数据集保存为xml时使用的缩进样式,c#,xml,dataset,C#,Xml,Dataset,我希望使用制表符,或者每个缩进级别至少使用2个以上的空格。IIRC当使用序列化写出一个类时,有一些选项可以调整它;但是在调用MyDataSet.WriteXml(filename)时,我看不到任何调整行为的方法。如果要影响正在保存的XML的布局,需要使用XmlTextWriter: XmlTextWriter xtw = new XmlTextWriter(filename, Encoding.UTF8); xtw.Formatting = Formatting.Indented; xtw.In

我希望使用制表符,或者每个缩进级别至少使用2个以上的空格。IIRC当使用序列化写出一个类时,有一些选项可以调整它;但是在调用
MyDataSet.WriteXml(filename)
时,我看不到任何调整行为的方法。如果要影响正在保存的XML的布局,需要使用
XmlTextWriter

XmlTextWriter xtw = new XmlTextWriter(filename, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 4;
xtw.IndentChar = '\t';
然后使用
XmlTextWriter
写出您的数据集:

MyDataSet.WriteXml(xtw);

如果要影响要保存的XML的布局,需要使用
XmlTextWriter

XmlTextWriter xtw = new XmlTextWriter(filename, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 4;
xtw.IndentChar = '\t';
然后使用
XmlTextWriter
写出您的数据集:

MyDataSet.WriteXml(xtw);

使用一个重载来接受
XmlWriter
,并传入一个配置有
XmlWriterSettings
对象的
XmlWriter
,该对象具有所需的选项



使用一个重载来接受
XmlWriter
,并传入一个配置有
XmlWriterSettings
对象的
XmlWriter
,该对象具有所需的选项



这不会产生4个制表符的缩进吗?;)这不会产生4个制表符的缩进吗?;)