码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C# xml、config文件添加自定义节点


    • 原config文件
    <configuration>
      <appSettings>
        <add key="111" value="222" />
        <add key="111" value="333" />
      appSettings>
    configuration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 添加recorders自定义节点
    XmlDocument doc = new XmlDocument();
    //加载配置文件
    doc.Load("D:\\U8SOFT\\Portal\\App.config");
    
    XmlNode recorders = doc.SelectSingleNode("configuration/recorders");
    
    if (recorders == null)
    {
        //找到configuration节点
        XmlNode configuration = doc.SelectSingleNode("configuration");
        //创建recorders节点,添加属性
        XmlElement xml_recorders = doc.CreateElement("recorders");
        xml_recorders.SetAttribute("enabled", "true");
        //创建recorder节点,添加属性
        XmlElement xml_recorder1 = doc.CreateElement("recorder");
        xml_recorder1.SetAttribute("key", "111");
        xml_recorder1.SetAttribute("value", "222");
        xml_recorder1.SetAttribute("type", "0");
        xml_recorders.AppendChild(xml_recorder1);
        //创建recorder节点,添加属性
        XmlElement xml_recorder2 = doc.CreateElement("recorder");
        xml_recorder2.SetAttribute("key", "111");
        xml_recorder2.SetAttribute("value", "222");
        xml_recorder2.SetAttribute("type", "1");
        xml_recorders.AppendChild(xml_recorder2);
        configuration.AppendChild(xml_recorders);
        //保存文件
        doc.Save("D:\\U8SOFT\\Portal\\App.config");
    
        recorders = doc.SelectSingleNode("configuration/recorders");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 修改后config文件
    
    <configuration>
      <appSettings>
        <add key="111" value="222" />
        <add key="111" value="333" />
      appSettings>
      <recorders enabled="true">
        <recorder key="111" value="222" type="0" />
        <recorder key="111" value="222" type="1" />
      recorders>
    configuration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    【数字IC应届生职业规划】Chap.1 IC行业产业链概述及代表企业大厂汇总
    Qt5开发及实例V2.0-第二十一章-Qt.Quick Controls开发基础
    本地跟单EA安装教程详解
    职场IT老鸟的几点小习惯
    Nacos介绍及安装启动
    MATLAB | 对随机信号进行统计分析,绘制频次直方图、频率分布图,与理论概率密度进行比较
    R语言data.table导入数据实战:data.table数据列名称的重命名(rename)
    LVS-DR模式 +keepalived
    红黑树(四) - C++实现
    Kotlin协程-select基础
  • 原文地址:https://blog.csdn.net/weixin_41622348/article/details/126966593
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号