xml文件保存与读取(最基础的方式)
一、从xml文件读取数据到Winform: 1、调用 using System.Xml; ? 2、XmlDocument xmlDoc = new XmlDocument(); 3、xmlDoc.Load(Application.StartupPath + "ParaConfig.xml"); 4、XmlElement xmlRoot = xmlDoc.DocumentElement; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Application.StartupPath + "ParaConfig.xml"); XmlElement xmlRoot = xmlDoc.DocumentElement; XmlNode login = xmlRoot.ChildNodes[0]; this.txbIPAddress.Text = login.Attributes["IP"].Value; this.txbUserName.Text = login.Attributes["Name"].Value; this.txbPassword.Text = login.Attributes["Password"].Value; XmlNode Setup = xmlRoot.ChildNodes[1]; this.cmbImageOrien.Text = Setup.Attributes["ImageOrien"].Value; 二、将Winform中的数据保存到xml文档中 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Application.StartupPath + "ParaConfig.xml"); XmlElement xmlRoot = xmlDoc.DocumentElement; XmlNode login = xmlRoot.ChildNodes[0]; login.Attributes["IP"].Value = this.txbIPAddress.Text; login.Attributes["Name"].Value = this.txbUserName.Text; login.Attributes["Password"].Value = this.txbPassword.Text; XmlNode Setup = xmlRoot.ChildNodes[1]; Setup.Attributes["ImageOrien"].Value = this.cmbImageOrien.Text; 保存与读取是同一种方法的不同表示; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |