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(" <person id=""+i.ToString("00000")+"">"); string[] temp = lines[i].Split(','); //加数据 list.Add(" <name>"+temp[0]+"</name>"); list.Add(" <phone>" + temp[1] + "</phone>"); list.Add(" </person>"); } list.Add("</root>"); File.WriteAllLines("xml.xml",list.ToArray(),Encoding.Default); }