1 XmlDocument xmldoc = new XmlDocument(); 2 xmldoc.Load("GoodsInfo.xml"); 3 XmlNode xnRoot = xmldoc.SelectSingleNode("商品信息"); 4 5 XmlNode node = xmldoc.CreateElement("商品"); 6 7 XmlElement element1 = xmldoc.CreateElement("名称"); element1.InnerText = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "Name").ToString(); node.AppendChild(element1); 8 9 XmlElement element2 = xmldoc.CreateElement("种类"); element2.InnerText = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "Type").ToString(); node.AppendChild(element2); 10 11 XmlElement element3 = xmldoc.CreateElement("价格"); element3.InnerText = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "Price").ToString(); node.AppendChild(element3); 12 13 XmlElement element4 = xmldoc.CreateElement("供货商"); element4.InnerText = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "Supplier").ToString(); node.AppendChild(element4); 14 15 xnRoot.AppendChild(node); 16 xmldoc.Save("GoodsInfo.xml");
用序列化操作吧,比较简单,你建一个实体类,用来放这些数据.要保存的时候直接把这个对象序列化成XML保存起来就行