string[] data1 = File.ReadAllLines("E:\\HtmlTxt.txt");//参考文件 string[] data2 = File.ReadAllLines("E:\\sqlTxt.txt");//数据文件 IEnumerable<string> data5 = data1.Except(data2); StringBuilder xmlResult = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); foreach (string m in data5) { string[] mm = m.Split(','); xmlResult.AppendFormat("<cityconfig><city>{0}</city><jc>{1}</jc><nbf>s</nbf><viewname>view_news_title_index_{1}</viewname></cityconfig>",mm[0],mm[1]); } //写入文件 try { //1.创建文件流 FileStream fileStream = new FileStream("E:\\diffHXml.xml",FileMode.Create); //2.创建写入器 StreamWriter streamWriter = new StreamWriter(fileStream); //3.将内容写入文件 streamWriter.WriteLine(xmlResult); //4.关闭写入器 streamWriter.Close(); //5.关闭文件流 fileStream.Close(); } catch { }
使用StringBuilder生成XML
原文链接:https://www.f2er.com/xml/296166.html