在WPF中操作xml文件的操作
一:读取xml文件
// 需要先声明 using System.Xml
XmlDocument MyXmlDocument = new XmlDocument();
MyXmlDocument.Load(path); // path 为xml文件的路径
XmlNode user_obj = MyXmlDocument.SelectSingleNode("root/user");
xml文件的结构图:
读取操作:
string a = user_obj.SelectSingleNode("value").InnerText // xml是树状结构
写入操作:
user_obj.SelectSingleNode("value").InnerText = "xxxx";
写入完要进行保存:
MyXmlDocument.Save(path);