创建xml的方法
using System.Xml;
string path = "E:/data.xml";
private void createxml()
{
XmlDocument xmldoc = new XmlDocument();
XmlDeclaration xmlSM = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmldoc.AppendChild(xmlSM);
XmlElement xml = xmldoc.CreateElement("", "Data", "");
xmldoc.AppendChild(xml);
XmlNode data = xmldoc.SelectSingleNode("Data");
xmldoc.Save(path);
}
添加新数据进xml中
private void use
{
createxml();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
XmlNode data = xmlDoc.SelectSingleNode("Data");
XmlElement dev = xmlDoc.CreateElement("Dev");
dev.SetAttribute("文本", "" + 变量 + "");
data.AppendChild(dev);
xmlDoc.Save(path);
}