zoukankan
html css js c++ java
XML 操作
using
System;
using
System.Xml;
namespace
Common
{
/**/
///
<summary>
///
Config 的摘要说明。
///
</summary>
public
class
Config
{
private
String msFileName
=
null
;
public
String ConfigFile
{
get
{
return
this
.msFileName;
}
set
{
if
(System.IO.File.Exists(value.Trim()))
{
this
.msFileName
=
value.Trim();
}
}
}
public
Config()
{
this
.msFileName
=
String.Empty;
}
public
Config(String ConfigFile)
{
this
.ConfigFile
=
ConfigFile.Trim();
}
public
bool
ReadConfig(String ContentName,
out
String ContentValue)
{
bool
bFlag
=
false
;
ContentValue
=
String.Empty;
if
(
!
System.IO.File.Exists(
this
.msFileName))
{
return
bFlag;
}
try
{
System.Xml.XmlDocument xmlDoc
=
new
System.Xml.XmlDocument();
xmlDoc.Load(
this
.msFileName);
System.Xml.XmlNode xmlNode
=
xmlDoc.SelectSingleNode(ContentName);
ContentValue
=
xmlNode.InnerText;
bFlag
=
true
;
}
catch
(XmlException xmle)
{
System.Console.WriteLine(xmle.Message);
}
return
bFlag;
}
public
bool
ReadConfig(String ContentName, String PropertyName,
out
String PropertyValue)
{
bool
bFlag
=
false
;
PropertyValue
=
String.Empty;
if
(
!
System.IO.File.Exists(
this
.msFileName))
{
return
bFlag;
}
try
{
XmlDocument xmlDoc
=
new
XmlDocument();
xmlDoc.Load(
this
.msFileName);
XmlNode xmlNode
=
xmlDoc.SelectSingleNode(ContentName);
XmlAttributeCollection xmlAttr
=
xmlNode.Attributes;
for
(
int
i
=
0
; i
<
xmlAttr.Count;
++
i)
{
if
(xmlAttr.Item(i).Name
==
PropertyName)
{
PropertyValue
=
xmlAttr.Item(i).Value;
bFlag
=
true
;
break
;
}
}
}
catch
(XmlException xmle)
{
System.Console.WriteLine(xmle.Message);
}
return
bFlag;
}
public
bool
WriteConfig(String ContentName, String ContentValue)
{
bool
bFlag
=
false
;
if
(
!
System.IO.File.Exists(
this
.msFileName))
{
return
bFlag;
}
try
{
System.Xml.XmlDocument xmlDoc
=
new
System.Xml.XmlDocument();
xmlDoc.Load(
this
.msFileName);
System.Xml.XmlNode xmlNode
=
xmlDoc.SelectSingleNode(ContentName);
xmlNode.InnerText
=
ContentValue;
xmlDoc.Save(
this
.msFileName);
bFlag
=
true
;
}
catch
(XmlException xmle)
{
System.Console.WriteLine(xmle.Message);
}
return
bFlag;
}
public
bool
WriteConfig(String ContentName, String PropertyName, String PropertyValue)
{
bool
bFlag
=
false
;
if
(
!
System.IO.File.Exists(
this
.msFileName))
{
return
bFlag;
}
try
{
XmlDocument xmlDoc
=
new
XmlDocument();
xmlDoc.Load(
this
.msFileName);
XmlNode xmlNode
=
xmlDoc.SelectSingleNode(ContentName);
XmlAttributeCollection xmlAttr
=
xmlNode.Attributes;
for
(
int
i
=
0
; i
<
xmlAttr.Count;
++
i)
{
if
(xmlAttr.Item(i).Name
==
PropertyName)
{
xmlAttr.Item(i).Value
=
PropertyValue;
bFlag
=
true
;
break
;
}
}
xmlDoc.Save(
this
.msFileName);
bFlag
=
true
;
}
catch
(XmlException xmle)
{
System.Console.WriteLine(xmle.Message);
}
return
bFlag;
}
}
}
查看全文
相关阅读:
Openstack Paste.ini 文件详解
Keystone controller.py & routers.py代码解析
YARN源码分析(三)-----ResourceManager HA之应用状态存储与恢复
YARN源码分析(四)-----Journalnode
YARN源码分析(四)-----Journalnode
YARN源码分析(四)-----Journalnode
YARN源码学习(五)-----NN,DN,RM在Ganglia上的监控实现机理
Confluence 6 配置一个 Confluence 环境
Confluence 6 审查日志的对象
Confluence 6 审查日志
原文地址:https://www.cnblogs.com/yiki/p/792041.html
最新文章
15数据结构与算法分析之---顺序队列
14数据结构与算法分析之---队列的定义
Mac 精品软件
Mac 精品软件
Core Location Framework学习
Core Location Framework学习
Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)以及各个Fragment之间的通信
Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)以及各个Fragment之间的通信
iOS 获取音频或是视频的时间
iOS 获取音频或是视频的时间
热门文章
iOS7 AVAudioRecorder不能录音
iOS7 AVAudioRecorder不能录音
openstack nova 源码解析 — Nova API 执行过程从(novaclient到Action)
Openstack Nova 源码分析 — RPC 远程调用过程
Openstack Nova 源码分析 — RPC 远程调用过程
VMware 接入 Openstack — 使用 Openstack 创建 vCenter 虚拟机
VMware 接入 Openstack — 使用 Openstack 创建 vCenter 虚拟机
Devstack — screen 调试工具的使用
Devstack — screen 调试工具的使用
Openstack Paste.ini 文件详解
Copyright © 2011-2022 走看看