标签:
phone.csv
zhangsan1,123456789 zhangsan2,123456789 zhangsan3,123456789
static void Main(string[] args) { //XML //XML就是一个文件,用来存储数据,比如csv文件 List<string> list = new List<string>(); list.Add("<?xml version=\"1.0\" encoding=\"gb2312\" ?>"); string[] lines = File.ReadAllLines("phone.csv", Encoding.Default); for (int i = 0; i < lines.Length; i++) { list.Add("\t<person id=\""+i.ToString("00000")+"\">"); string[] temp = lines[i].Split(‘,‘); //加数据 list.Add("\t\t<name>"+temp[0]+"</name>"); list.Add("\t\t<phone>" + temp[1] + "</phone>"); list.Add("\t</person>"); } list.Add("</root>"); File.WriteAllLines("xml.xml",list.ToArray(),Encoding.Default); }
标签:
原文地址:http://www.cnblogs.com/zychengzhiit1/p/4765703.html