標籤:
public partial class Form1 : Form { private string songlocation = @"D:\codeDemo\xml\xmlText\xmlDemo.xml"; private string[] songlist = new string[] {"a","b","c" }; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { using (XmlTextWriter xwriter = new XmlTextWriter(songlocation, Encoding.UTF8)) { //縮排, 不加這個,xml就是一行 xwriter.Formatting = Formatting.Indented; xwriter.WriteStartDocument(); xwriter.WriteStartElement("myplayer"); xwriter.WriteStartElement("playingsongs"); xwriter.WriteAttributeString("total", songlist.Length.ToString()); for (int i = 0; i < songlist.Length; i++) { xwriter.WriteAttributeString("song" + i.ToString(), songlist[i].ToString()); } xwriter.WriteEndElement(); xwriter.WriteEndElement(); xwriter.WriteEndDocument(); //重新整理流 xwriter.Flush(); xwriter.Close(); } } }
來源:http://social.microsoft.com/Forums/es-ES/visualcshartzhchs/thread/f0b1f040-724c-48d3-aa59-b828e45ddeca
用XmlTextWriter寫出的XML檔案沒有換行,用記事本開啟XML檔案的時候都寫在了一行上,請問怎樣加入換行!