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;
}
}
}
查看全文
相关阅读:
AtCoder Beginner Contest 113 D Number of Amidakuji
UVA
mt19937 -- 高质量随机数
牛客网NOIP赛前集训营-提高组(第七场)C 洞穴
牛客OI周赛4-提高组 C 战争(war)
牛客OI周赛4-提高组 B 最后的晚餐(dinner)
bzoj 4318 || 洛谷P1654 OSU!
Tourists Codeforces
bzoj 1791 [Ioi2008]Island 岛屿
洛谷 P2231 [HNOI2002]跳蚤
原文地址:https://www.cnblogs.com/yiki/p/792041.html
最新文章
POJ3696 The Luckiest Number
LightOJ1199 Partition Game
LightOJ 1253 Misere NIM(反NIM博弈)
LightOJ 1186 Icreable Chess(Nim博弈)
LightOJ1355 Game Of CS(green 博弈)
HDU1079 Calender Game
2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)
Codeforces 1079 E
牛客OI周赛6-提高组 B 践踏
牛客OI周赛6-提高组 A 大法师与魔法石
热门文章
UVA
2018 AICCSA Programming Contest
Semana i 2018
EOJ Monthly 2018.11 D. 猜价格
Codeforces 1077 F2
Codeforces 1062 E
Codeforces 1071 C
Codeforces 1076 E
Codeforces 1073 E
Codeforces 1043 F
Copyright © 2011-2022 走看看