XmlDocument xmlDoc = new XmlDocument();
XmlNode xmlNode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); xmlDoc.AppendChild(xmlNode); //加入根元素 XmlElement xmlElem = xmlDoc.CreateElement("", "ROOT", ""); //xmlElem.SetAttribute("color", "red"); //xmlElem.InnerText = "根结点"; xmlDoc.AppendChild(xmlElem); XmlElement xmlelem_c = xmlDoc.CreateElement("FIRST"); xmlelem_c.SetAttribute("noe", "First nod"); xmlelem_c.InnerText = "第1节点"; xmlElem.AppendChild(xmlelem_c); xmlDoc.Save("d:\\t.xml");