C#读写xml文件的简单例子

发布时间:2019-07-15编辑:脚本学堂
分享一个c#实现的读写xml配置文件的例子,学习下xmlDocument的用法,有需要的朋友参考下吧。

c#实现读取与写入xml配置文件。
代码:
 

复制代码 代码示例:
//读配置文件
XmlDocument doc = new XmlDocument();
doc.Load("blog.xml");
XmlNode url = doc.SelectSingleNode("博客/广告地址");
texturl.Text = url.InnerText;
 
XmlNode Name = doc.SelectSingleNode("博客/用户名1");
name = Name.InnerText;
 
XmlNode Password = doc.SelectSingleNode("博客/密码1");
password = Password.InnerText;
 
XmlNode dbid = doc.SelectSingleNode("博客/DBID");
DBID = int.Parse(dbid.InnerText);
 
//写配置文件
XmlDocument doc = new XmlDocument();
doc.Load("blog.xml");
XmlNode xiugai = doc.SelectSingleNode("博客");
xiugai["DBID"].InnerText = DBID.ToString();   //修改值
doc.Save("blog.xml");

您可能感兴趣的文章:
C#读写xml配置文件(LINQ操作实例)
C#读写xml文件的实例代码
asp.net读写xml文件的代码一例