C# 在LINQ to XML中将XML文件转换为CSV文件的例子源码
代码说明:
C# 在LINQ to XML中将XML文件转换为CSV文件的例子源码,转换的结果请参考如图所示: private void button1_Click(object sender, EventArgs e) {//在LINQ to XML中将XML文件转换为CSV文件 TextReader MyReader = new StringReader(this.textBox1.Text); XElement MyCustomers= XElement.Load(MyReader); MyReader.Close(); string MyInfo = (from MyElement in MyCustomers.Elements("客户") select String.Format("{0},{1},{2},{3},{4}", (string)MyElement.Element("客户ID"), (string)MyElement.Element("公司名称"), (string)MyElement.Element("城市") + (string)MyElement.Element("地址"), (string)MyElement.Element("联系人姓名"), Environment.NewLine ) ).Take(10).Aggregate(new StringBuilder(),(MySubString, MyString)=>MySubString.Append(MyString),MySubString=>MySubString.ToString()); MessageBox.Show(MyInfo, "信息提示"); }
下载说明:请别用迅雷下载,失败请重下,重下不扣分!