用XmlTextWriter写出的XML文件没有换行,用记事本打开XML文件的时候都写在了一行上,请问怎样加入换行!

来源:http://social.microsoft.com/Forums/es-ES/visualcshartzhchs/thread/f0b1f040-724c-48d3-aa59-b828e45ddeca

这个是我的程序代码?请问怎样让写出的XML文件里都一行一行的!

using (XmlTextWriter xwriter = new XmlTextWriter(songlocation , null))
            {
                xwriter.WriteStartDocument();
                xwriter.WriteStartElement("myplayer");
                xwriter.WriteStartElement("playingsongs");
                xwriter.WriteAttributeString("total",songlist.Count .ToString ());
                for (int i = 0; i < songlist.Count ;i++ )
                {
                    xwriter.WriteAttributeString("song"+i.ToString (),songlist[i ].ToString ());
                }
                xwriter.WriteEndElement();
                xwriter.WriteEndElement();
                xwriter.WriteEndDocument();
                xwriter.Flush();
                xwriter.Close();
            }

// 写入XML文档            

            XmlTextWriter writer = null;
            try
            {

                writer = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("Log");
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }

 

 

posted on 2010-05-03 20:19  大宝pku  阅读(4064)  评论(1编辑  收藏  举报

导航