C# xml格式整理工具

拖入xml的目录文件,自动格式化期目录下的xml格式.适合文本处理过后的工具调整.

csdn下载地址:

http://download.csdn.net/detail/kijl000/4106236

源码晚上写上去.

            // 获取指定文件夹目录 

            string filepath = listBox1.Items[0].ToString();

            DirectoryInfo baseDir = new DirectoryInfo(filepath);

            // 获取指定文件夹下的所有文件。

            // 如果你需要获取特定格式的文件,如.html 结尾的,可以写成 baseDir.GetFiles("*.html");

            FileInfo[] files = baseDir.GetFiles("*.xml");

            // 定义文件名字符串

            progressBar1.Visible = true;

            progressBar1.Maximum = files.Length;

            progressBar1.Minimum = 0;

            string fileNames = string.Empty;

            for (int i = 0; i < files.Length; i++)

            {

                // 获取每个文件名,并记录到 字符串 fileNames 里

                // 如果需要获取文件的完整路径名, files[i].FullName;

                //fileNames += files[i].FullName + ",";



                string xmlfile = @files[i].FullName;

                MemoryStream mstream = new MemoryStream(1024);

                XmlTextWriter writer = new XmlTextWriter(mstream, null);

                XmlDocument xmldoc = new XmlDocument();

                writer.Formatting = Formatting.Indented;

                xmldoc.Load(xmlfile);

                xmldoc.WriteTo(writer);

                writer.Flush();

                writer.Close();

                Encoding encoding = Encoding.GetEncoding("utf-8");

                listBox1.Items.Add("正在处理:" + @files[i].FullName);

                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                progressBar1.Value = i+1;

                //this.ListBox1.Text += "\r\n正在处理:" + @files[i].FullName + "...\r\n";

                //File myfile = new file

                xmldoc.Save(@files[i].FullName);

                mstream.Close(); 

            }

            // 显示到 Label 标签上

            listBox1.Items.Add("Finish!!!!");

            listBox1.SelectedIndex = listBox1.Items.Count - 1;

  

你可能感兴趣的:(xml)