码农知识堂 - 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
  • 相关阅读:
    【Linux】四、Linux 进程概念(二)|普遍操作系统的进程状态(运行、阻塞、挂起)|Linux的具体进程状态|僵尸进程|孤儿进程
    使用 C# 读取 zip 压缩包解压文件的方法及注意事项
    node 之 express 框架(初级)
    《Webpack 5 基础配置》- 禁止在出现编译错误或警告时,覆盖浏览器全屏显示
    什么是“path”环境变量?path的作用是什么?
    在CentOS7系统下升级 Magento 从 2.3.2 到 2.4.3-p1
    python多进程与多线程
    Go编程:使用 Colly 库下载Reddit网站的图像
    使用Detectron2目标检测&特征提取
    旅游景区开发小程序有什么好处
  • 原文地址: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号