标签:
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(); } } }
用XmlTextWriter写出的XML文件没有换行,用记事本打开XML文件的时候都写在了一行上,请问怎样加入换行!
标签:
原文地址:http://www.cnblogs.com/leiliu-lucifer/p/5458977.html