標籤:
例子:
<add key="IsEmptyDGAddRootText" value="" /> <!--是否可以修改歸檔狀態檔案 false: 不能修改 true 可以修改--> <add key="IsEnableEditArchiveEntry" value="true" /> <!--是否輸出調用日誌--> <add key="IsEnableOutPutLog" value="true" /> <!--是否調試狀態--> <add key="IsDebug" value="true" /> <!--調試狀態使用者Id--> <add key="DebugUserId" value="dajkTest1" /> <!--調試狀態使用者密碼--> <add key="DebugUserPwd" value="dajkTest1***" />
做法:
XmlDocument xdoc = new XmlDocument(); //建立XML執行個體 if (File.Exists("web.config")) {
//如果檔案存在就操作 xdoc.Load("web.config"); XmlNodeList adds = xdoc.SelectNodes("//appSettings/add");
//建立讀取節點的方法並且找到對應節點(appSettings下的add子節點)
if (this.rbEntryStateY.Checked) {
//找到對應第11個節點的第一個屬性並且修改值 adds[11].Attributes[1].Value = "true"; } else if (this.rbEntryStateN.Checked) { adds[11].Attributes[1].Value = "false"; } if (this.rbLogY.Checked) { adds[12].Attributes[1].Value = "true"; } else if (this.rbLogN.Checked) { adds[12].Attributes[1].Value = "false"; } if (this.rbDebugStateY.Checked) { adds[13].Attributes[1].Value = "true"; } else if (this.rbDebugStateN.Checked) { adds[13].Attributes[1].Value = "false"; } adds[14].Attributes[1].Value = DebugUserId; adds[15].Attributes[1].Value = DebugUserPwd; //全部修改完畢,儲存XML檔案 xdoc.Save("web.config"); }
使用C#讀取XML節點,修改XML節點