zoukankan      html  css  js  c++  java
  • xml配置文件的读写

    using System.Xml;

    //----------------------------------------------读出XML文件中的节点值

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(Application.StartupPath + "\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
    //得到顶层节点列表
    if (xmlDoc.DocumentElement != null) {
    XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
    foreach (XmlElement el in from XmlElement element in topM where element.Name.ToLower() == "appsettings" select element.ChildNodes into nodelist where nodelist.Count > 0 from XmlElement el in nodelist where el != null select el) {
    if (el.Attributes["key"].Value == "SecurityKey") {
    txtSecurityKey.Text = el.Attributes["value"].Value;
    }
    if (el.Attributes["key"].Value == "ClientNo") {
    txtClientCode.Text = el.Attributes["value"].Value;
    }
    if (el.Attributes["key"].Value == "ClientType") {
    txtClientType.Text = el.Attributes["value"].Value;
    }
    }
    }

    //---------------------------------------------写入XML文件的值

    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.Load(Application.StartupPath + "\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
    //得到顶层节点列表
    if (xmlDoc.DocumentElement != null) {
    XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
    foreach (XmlElement el in from XmlElement element in topM where element.Name.ToLower() == "appsettings" select element.ChildNodes into nodelist where nodelist.Count > 0 from XmlElement el in nodelist where el != null select el) {
    if (el.Attributes["key"].Value == "SecurityKey"){
    el.Attributes["value"].Value = txtSecurityKey.Text.Trim();
    }
    if (el.Attributes["key"].Value == "ClientNo") {
    el.Attributes["value"].Value = txtClientCode.Text.Trim();
    }
    if (el.Attributes["key"].Value == "ClientType"){
    el.Attributes["value"].Value = txtClientType.Text.Trim();
    }
    }
    }
    xmlDoc.Save(configFileName);

  • 相关阅读:
    [CSP校内集训]hotel
    DP小技巧——悬线法
    [SDOI2015]寻宝游戏/异象石(LCA)
    [HAOI2006]旅行
    [SDOI2013]泉(搜索+hash+容斥)
    [NOIP校内集训]home
    [AHOI2014/JSOI2014]骑士游戏(SPFA的本质)
    欧拉函数模板
    开学考试题8:神奇的集合(multiset) 动态开点线段树
    开学考试题5:2017黑龙江省选
  • 原文地址:https://www.cnblogs.com/qingqingqing/p/4455392.html
Copyright © 2011-2022 走看看