哪位大虾能提供一些用C#读写删改XML文件内容的资料啊?救小弟一命!! http://community.csdn.net/Expert/topic/3147/3147356.xml?temp=.589184

解决方案 »

  1.   

    XmlDocument xDoc = new XmlDocument();
    xDoc.Load(Application.ExecutablePath + ".config");

    XmlNode xNode;
    XmlElement xElem1;
    XmlElement xElem2; xNode =  xDoc.SelectSingleNode("//appSettings");

    xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='UserName']");
    if ( xElem1 != null ) xElem1.SetAttribute("value",this.txtUserName.Text);
    else
    {
    xElem2 = xDoc.CreateElement("add");
    xElem2.SetAttribute("key","UserName");
    xElem2.SetAttribute("value",this.txtUserName.Text);
    xNode.AppendChild(xElem2);
    }
       
    xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='Password']");
    if ( xElem1 != null ) xElem1.SetAttribute("value",this.txtPassword.Text);
    else
    {
    xElem2 = xDoc.CreateElement("add");
    xElem2.SetAttribute("key","Password");
    xElem2.SetAttribute("value",this.txtPassword.Text);
    xNode.AppendChild(xElem2);
    }
    xDoc.Save(Application.ExecutablePath + ".config"); this.button1.Enabled = false;
      

  2.   

    谢谢qqqdong的回复,问题解决。