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;
}
}
}
查看全文
相关阅读:
markdown的使用说明
iOS开发关于真机—App发布证书和调试证书配置
iOS开发UI篇—屏幕适配autoResizing autoLayout和sizeClass图文详解
iOS开发UI篇—模仿ipad版QQ空间登录界面
iOS开发UI篇—iPad开发中得modal介绍
iOS开发UI篇—popoverController使用注意
iOS开发UI篇—popoverController简单介绍
C语言:二十四 防止头文件被重复包含#ifndef #define #endif
C语言:二十五 函数中的static例子
C语言:C运算符优先级
原文地址:https://www.cnblogs.com/yiki/p/792041.html
最新文章
Block传值
界⾯间传值
如何得到自定义UITableViewCell中的按钮所在的cell
iOS 中断点调试
SDWebImage播放GIF图
UIScrollView不接受UITouch事件的解决方法
Xcode中Info.plist文件各个键的作用说明
iOS 关于横竖屏幕的问题
iOS TabBar 隐藏的问题
iOS @protocol UIContentContainer <NSObject>
热门文章
iOS button 事件不响应
oc 生成并持有对象的强引用
HTML之标签类型
HTML之选择器
ios 加载.bundle文件里的图片
ios 多继承的两种方法
如果编译时存在Duplicated的问题,可以尝试删掉-ObjC和-all_load单独设置-force_load只加载使 到的类别的静态库。
iOS ReactiveCocoa 最全常用API整理(可做为手册查询)
iOS开发拓展篇——如何把项目托管到GitHub
C语言指针学习笔记
Copyright © 2011-2022 走看看