C# 保存xml文档
XDocument document = new XDocument(new XDeclaration("1.0","utf-8",null)); XElement root = new XElement("root"); root.SetAttributeValue("Name", "ConfigFileName"); root.SetAttributeValue("Date", DateTime.Now.ToString()); XElement configList=new XElement("CONFIGLIST"); configList.SetAttributeValue("ver", "1.0"); XElement sc = new XElement("SC"); sc.SetElementValue("NAME", "SC1"); sc.SetElementValue("VALUE", "1"); configList.Add(sc); XElement sc2 = new XElement("SC"); sc2.SetElementValue("NAME", "SC2"); sc2.SetElementValue("VALUE", "2"); configList.Add(sc2); root.Add(configList); document.Add(root); document.Save(@"C:\Users\TEST\SCCONFIG.xml");