zoukankan      html  css  js  c++  java
  • 用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();
                }

     

  • 相关阅读:
    poj 2488 A Knight's Journey( dfs )
    poj 2676 Sudoku ( dfs )
    poj 3087 Shuffle'm Up ( map 模拟 )
    poj 1426 Find The Multiple( bfs )
    poj 3126 Prime Path( bfs + 素数)
    Atcoder ARC-063
    Atcoder ARC-062
    Atcoder ARC-061
    Atcoder ARC-060
    Atcoder ARC-058
  • 原文地址:https://www.cnblogs.com/dabaopku/p/1726746.html
Copyright © 2011-2022 走看看