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. python3 生成器&迭代器

    #Author by Andy#_*_ coding:utf-8 _*_import timefrom collections import Iterable#列表生成式def func(): lis ...

  2. 【oracle】 oracle学习笔记1--安装与登录

    由于机器配置原因,加上也是自学,所以就没必要安装专业版的oracle,于是就安装的oracle xe版本 下载地址:http://www.oracle.com/technetwork/database ...

  3. [WPF]MenuItem右侧空白

    <Window> <Grid Background="SteelBlue"> <Grid.ContextMenu> <ContextMen ...

  4. 比CMD更强大的命令行WMIC

    先决条件:a. 启动Windows Management Instrumentation服务,开放TCP135端口.b. 本地安全策略的“网络访问: 本地帐户的共享和安全模式”应设为“经典-本地用户以 ...

  5. .net乱码问题

    最近在给一个客户做framwwork版本升级,从1.0版本升级到4.0版本,发现最大的问题就是乱码. 在1.0版本下,gb2312编码能够运行得很好,可是升级到4.0后就都是乱码. 随后将webcon ...

  6. 使用robot frame selenium中遇到的问题汇总

    1.问题:robot运行时提示:[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser i ...

  7. Maven中的DependencyManagement和Dependencies

    Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式.通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素.使用p ...

  8. DataTable数据导出CSV文件

    public static void SaveAsExcel(DataTable dt1) { //System.Windows.Forms.SaveFileDialog sfd = new Syst ...

  9. 关于RequireJS与AngularJS的集成文档

    为什么要整合RequireJS RequireJS是一个Javascript 文件和模块框架,通过模块的方式来配置js文件之间的依赖关系,遵守的是CommonJS的AMD标准. 在开发的时候则无需关注 ...

  10. oracle异常:ORA-01422: exact fetch returns more than requested

    ORA-01422: exact fetch returns more than requested 神奇的错误,困扰了我一个下午. 问题描述:明明只有一行记录,结果是报了多条记录的错误.令我百思不得 ...