zoukankan
html css js c++ java
读取XML类 (XmlHelper)
XmlHelper
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Xml;
namespace
System.Bwch.XmlConfig
{
/**/
///
<summary>
///
读取XML配置文件类
///
</summary>
public
class
XmlHelper
{
private
string
strXmlPath
=
""
;
//
Xml文档路径
private
XmlDocument xmlDoc;
//
XML文档
/**/
///
<summary>
///
初始化ReadXml类
///
</summary>
///
<param name="XMLPath">
XML文件路径
</param>
public
XmlHelper(
string
XMLPath)
{
if
(
!
System.IO.File.Exists(XMLPath))
{
throw
new
Exception(
"
没有找到指定的路径:
"
+
XMLPath
+
"
的XML文档
"
);
}
strXmlPath
=
XMLPath;
xmlDoc
=
new
XmlDocument();
xmlDoc.Load(XMLPath);
}
/**/
///
<summary>
///
读取XML文件指定键值的value值
///
</summary>
///
<param name="XMLNodePath">
键值的路径,格式为(根节点/节点/子节点)
</param>
///
<param name="valueName">
指定键值的属性名称
</param>
///
<returns>
value值
</returns>
public
string
ReadXmlValue(
string
XMLNodePath,
string
valueName)
{
try
{
XmlElement xml
=
(XmlElement)xmlDoc.SelectSingleNode(XMLNodePath);
return
xml.GetAttribute(valueName);
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
}
/**/
///
<summary>
///
写XML指定节点的
///
</summary>
///
<param name="XmlNodePath">
键值路径,格式为((根节点/节点/子节点))
</param>
///
<param name="valueName">
属性名称
</param>
///
<param name="Value">
属性
</param>
///
<returns></returns>
public
bool
WriteXmlValue(
string
XmlNodePath,
string
valueName,
string
Value)
{
try
{
XmlElement xml
=
(XmlElement)xmlDoc.SelectSingleNode(XmlNodePath);
xml.SetAttribute(valueName, Value);
//
设置
xmlDoc.Save(strXmlPath);
//
保存
return
true
;
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
}
/**/
///
<summary>
///
读取XML键值
///
</summary>
///
<param name="XmlNodePath">
键值路径,格式为((根节点/节点/子节点))
</param>
///
<returns></returns>
public
string
ReadXmlKey(
string
XmlNodePath)
{
try
{
XmlElement xml
=
(XmlElement)xmlDoc.SelectSingleNode(XmlNodePath);
return
xml.InnerText;
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
}
/**/
///
<summary>
///
写XML键值
///
</summary>
///
<param name="XmlNodePath">
键值路径,格式为((根节点/节点/子节点))
</param>
///
<param name="Value">
值
</param>
///
<returns></returns>
public
bool
WriteXmlKey(
string
XmlNodePath,
string
Value)
{
try
{
XmlElement xml
=
(XmlElement)xmlDoc.SelectSingleNode(XmlNodePath);
xml.InnerText
=
Value;
xmlDoc.Save(strXmlPath);
return
true
;
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
}
}
}
查看全文
相关阅读:
Java 面向对象(十五)
py+selenium 自动判断页面是否报错并显示在自动化测试报告【原创】
跨站脚本攻击(反射型)笔记(四)——较罕见的操作
requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))【已解决】
py+selenium+IE 批量执行脚本10几分钟,IE会卡住【无解,提供绕过方法】
py+selenium+IE10【IE已停止工作】【已解决】
打开pycharm,提示invalid Log Path【已解决】
python+selenium 批量执行时出现随机报错问题【已解决】
python爬取新浪股票数据—绘图【原创分享】
py+selenium IE 用driver.close()却把两个窗口都关了【已解决】
原文地址:https://www.cnblogs.com/bwch_xm/p/1607046.html
最新文章
Centos7下vim配置solarized异常
Linux常用命令
获取Linux相关帮助信息
Linux硬盘分区
Linux系统安装-CentOS6.8
CSS 实现单行、多行文本溢出显示省略号
MongoDB 用户角色与权限管理
MAC下MySQL服务重启
Express 格式化输出HTML
一头扎进Node(三)
热门文章
iTerm2 的相关配置
Mac去除终端计算机名称
JavaScript 对象详解
JavaScript 浅克隆与深度克隆
JavaScript 常见正则表达式
Emmet语法规则
JavaScript
Java 面向对象(十七)
Java 面向对象(十六)
XML
Copyright © 2011-2022 走看看