2009-12-11 40 views

回答

2

您需要使用XmlTextWriter如果你想影響你的XML佈局被保存:

XmlTextWriter xtw = new XmlTextWriter(filename, Encoding.UTF8); 
xtw.Formatting = Formatting.Indented; 
xtw.Indentation = 4; 
xtw.IndentChar = '\t'; 

,然後寫出你的數據使用XmlTextWriter集:

MyDataSet.WriteXml(xtw); 
+0

那不是產生4個製表符的縮進? ;) – 2009-12-11 22:06:43

+0

是的,在這種情況下,它會。根據需要調整:-) – 2009-12-11 22:09:18

1

使用一個的接受XmlWriter的過載,並傳入配置有XmlWriterSettings對象的XmlWriter,該對象具有所需的選項。


XmlWriterSettings settings = new XmlWriterSettings 
          { 
           Indent = true, 
           IndentChars = "\t" 
          }; 
using (var writer = XmlWriter.Create("file.xml", settings)) 
{ 
    ds.WriteXml(writer); 
} 
相關問題