??
public static void insertData(string id,string name,string password) { XmlDocument xml = new XmlDocument(); xml.Load(@"E:a.xml"); XmlNode root = xml.SelectSingleNode("User"); XmlElement User = xml.CreateElement("user"); User.SetAttribute("id",id); XmlElement Name = xml.CreateElement("name"); Name.InnerText = name; XmlElement Password = xml.CreateElement("password"); Password.InnerText = password; root.AppendChild(User); User.AppendChild(Name); User.AppendChild(Password); xml.Save(@"E:a.xml"); } public static void createXml(string filePath) { if (!File.Exists(filePath)) { FileStream fs = File.Create(filePath); fs.Flush(); fs.Close(); FileInfo fi = new FileInfo(filePath); StreamWriter sw = fi.AppendText(); string description = "<?xml version="1.0" encoding="utf-8" ?> "; sw.WriteLine(description); sw.WriteLine("<User></User>"); sw.Flush(); sw.Close(); } } static void Main(string[] args) {
createXml(@"E:a.xml"); for(int i=0;i<5;i++){ insertData(i.ToString(),"name"+i,"ppp"+i); }
} (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|