就看你需要如何合并了。
//以前收集的代码,平时用linq to xml //第一种方式 序列化 [XmlRoot("products")] public class Products { [XmlElement("product")] public Product[] Items { get; set; } } public class Product { [XmlAttribute(AttributeName = "name")] public string Name { get; set; } [XmlAttribute(AttributeName = "price")] public decimal Price { get; set; } [XmlAttribute(AttributeName = "supplier")] public decimal Supplier { get; set; } } using (TextReader reader = new StreamReader("1.xml")) { var serializer = new XmlSerializer(typeof(Products)); var items = (Products)serializer.Deserialize(reader); if (items != null) { // items.Items } else { } } //第二种方式 linq to xml XDocument xdoc = XDocument.Load("1.xml"); XElement root = xdoc.Root; //products IEnumerable<XElement> ps = root.Elements(); //product(集合)下的所有元素 foreach (var item in ps) { IEnumerable<XAttribute> attrs = item.Attributes(); //每个product下每个属性(集合) //foreach (var attr in attrs) //{ // //stringBuilder.AppendFormat("{0}:{1}\n", attr.Name, attr.Value); //} }