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;
}
}
}
查看全文
相关阅读:
scrapy爬取相似页面及回调爬取问题(以慕课网为例)
爬取网易云课堂、网易公开课课程数据
用户行为数据分析笔记
redis学习笔记
索引原理及几种索引类型区别
平衡二叉树,B树,B+树的概念及区别
RF, GBDT, XGB区别
无偏估计
Redis分布式锁的正确实现方式
Mybatis 你了解多少?
原文地址:https://www.cnblogs.com/yiki/p/792041.html
最新文章
【个人】爬虫实践,利用xpath方式爬取数据之爬取虾米音乐排行榜
利用Python统计微信联系人男女比例以及简单的地区分布
java 读写ini配置文件
Java 利用递归删除文件以及文件夹
Java操作redis简单示例
C# 实现软件的重启
C# 模拟按下回车键自动登录
windows10下的docker 修改镜像位置和卷内容
vs扩展
windows的host文件
热门文章
vue devtools 包
zipkin-client:brave核心代码思路整理
SolrCloud配置
用Intellij idea搭建solr调试环境
solr导入数据库数据
Struts2.3+Spring3.2+Hibernate4.2框架搭建
macOS 自动修改mac地址脚本
通过try、except和else的使用来使Python程序更加“强壮”
Python 的“+”和append在添加字符串时候的区别
scrapy爬虫框架windows下的安装问题
Copyright © 2011-2022 走看看