一、从xml文件读取数据到Winform:
1、调用 using System.Xml;
2、XmlDocument xmlDoc = new XmlDocument();
3、xmlDoc.Load(Application.StartupPath + "\\ParaConfig.xml");
4、XmlElement xmlRoot = xmlDoc.DocumentElement;
5、XmlNode login = xmlRoot.ChildNodes[0];
6、 this.txb1.Text = login.Attributes["1"].Value;
this.txb2.Text = login.Attributes["2"].Value;
XmlNode Setup = xmlRoot.ChildNodes[1];
this.cmb1.Text = Setup.Attributes["3"].Value;
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; //保存上面的修改 xmlDoc.Save(Application.StartupPath + "\\ParaConfig.xml");
保存与读取是同一种方法的不同表示;
原文地址:https://www.cnblogs.com/kaqiu/p/9120869.html
时间: 2024-10-05 03:38:12