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);

xml配置文件的读写的更多相关文章

  1. C#中读写Xml配置文件常用方法工具类

    场景 有时需要使用配置文件保存一些配置的属性,使其在下次打开时设置仍然生效. 这里以对xml配置文件的读写为例. 1.读取XML配置文. 2.写入XML配置文件. 3.匹配 XPath 表达式的第一个 ...

  2. List 拆分集合与 读写XML配置文件

    有时候会出现需要将一个集合分成所干个集合,依次再对每组集合进行处理,想了想,用 Linq 处理就很方便 ); ).Take(); //第一组 ).Take(); //第二组 ; i < time ...

  3. 配置文件Java读写

    今天把配置文件的Bug修复了,总结一下Java配置文件如何读写 配置文件的格式 以.properties后缀结尾,内容不出现空格和双引号 //config.properties Driver=com. ...

  4. Mybatis 源码分析--Configuration.xml配置文件加载到内存

    (补充知识点: 1 byte(字节)=8 bit(位) 通常一个标准英文字母占一个字节位置,一个标准汉字占两个字节位置:字符的例子有:字母.数字系统或标点符号) 1.创建SqlSessionFacto ...

  5. 转-springAOP基于XML配置文件方式

    springAOP基于XML配置文件方式 时间 2014-03-28 20:11:12  CSDN博客 原文  http://blog.csdn.net/yantingmei/article/deta ...

  6. xml 配置文件规范 校验

    背景:做的数据同步框架,数据同步种类通过xml配置文件添加.为了系统的稳定性,我们只能认为将来写这个运行配置xml的人是一个傻瓜,那么对xml格式校验就很重要. 通过dom4j,是可以完成对xml格式 ...

  7. Spring中加载xml配置文件的六种方式

    Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog  因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...

  8. 史上最全web.xml配置文件元素详解

    一.web.xml配置文件常用元素及其意义预览 <web-app> <!--定义了WEB应用的名字--> <display-name></display-na ...

  9. Spring XML配置文件示例(二)——web.xml

    <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" ...

随机推荐

  1. Android NDK 初探,生成so文件以及调用so文件方法

    因为最近业务上涉及安全的问题 然后有一些加密解密的方法和key的存储问题 本来想存储到手机里面,但是网上说一般敏感信息不要存储到手机Sdcard上 而且我这个如果从网络建立通信获取的话,又太耗时,所以 ...

  2. zookeeper、kafka、storm install

    安装顺序 zookeeper,kafka,storm install zookeeper 1.上传tar包,解压tar tar -zxvf   zookeeper-3.4.6.tar.gz 2.复制 ...

  3. asp.net登录时验证码的制作与验证

    1.新建一个页面,ImageCode.aspx 2.在Page_Load中添加如下代码 string tmp = RndNum(4); HttpCookie a = new HttpCookie(&q ...

  4. mysql 查询数据库表结构

    1. mysql> describe tmp_log; +----------+------------------+------+-----+---------+--------------- ...

  5. Webstorm 下的Angular2.0开发之路

    人一旦上了年纪,记忆力就变得越来越不好. 最近写了许多的博文,倒不是为了给谁看,而是方便自己来搜索,不然一下子又忘记了. 如果恰巧帮助到了你,也是我的荣幸~~~~~~~~~~~~ 废话不多说,看正题~ ...

  6. python 学习2

    在1的基础上 settings.py blog/models.py: 打开一个cmd, net start mysql ,启动mysql服务 mysql -uroot -p 再在py_fir目录下打开 ...

  7. ASP.NET MVC多表单提交

    多表单提交需要写清路径,以便主程序可以找到 方法一:直接写路径, action="~/Home/other1"   "~"表示从根目录开始 方法2:@using ...

  8. hexo deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  9. uva 820(最大流)

    最大流的裸题,直接贴了模板. #include <cstdio> #include <iostream> #include <sstream> #include & ...

  10. 关于rem的学习

    网页常见单位px.em.rem:其中rem是css3新出的单位,官网是这样定义的:“font size of the root element”,意思是:相对长度单位,相对于根元素(即html元素)f ...