The XML file written with XmlTextWriter does not wrap, when you open the XML file with Notepad is written on a line, how to add line!

Source: Internet
Author: User


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))
            {
                / / Indent, without this, xml is a line
                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();

                / / Refresh the stream
                xwriter.Flush();
                xwriter.Close();
            }
        }
    } 


Source: Http://social.microsoft.com/Forums/es-ES/visualcshartzhchs/thread/f0b1f040-724c-48d3-aa59-b828e45ddeca



The XML file written with XmlTextWriter does not wrap, when you open the XML file with Notepad is written on a line, how to add line!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.