xml文件操作( 讀寫)

private void changeConfig()
  {
    XmlDocument xDoc = new XmlDocument();
   string strName = AppDomain.CurrentDomain.BaseDirectory.ToString()+"Web.config";
   xDoc.Load(strName);
   XmlNodeList xnl = xDoc.GetElementsByTagName("add");
//   foreach( XmlNode xn in xnl)
//   {
//    Response.Write(xn.Attributes["v"].Value.ToString());
//   }
   for(int i=0; i<xnl.Count; i++)
   {
    xnl[i].Attributes["key"].Value = "Sql1";
    xnl[i].Attributes["value"].Value = "Server=.;Database=test;uid=sa;pwd=123";
   }
   xDoc.Save(strName);

  } 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章