读写xml文件的2个小函数
#region 读写xml文件的2个小函数,2005 4 2 by hyc
public void SetXmlFileValue(string xmlPath,string AppKey,string AppValue)//写xmlPath是文件路径+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if ( xElem1 != null )
{
xElem1.SetAttribute("value",AppValue);
}
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key",AppKey);
xElem2.SetAttribute("value",AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(xmlPath);
}
public void GetXmlFileValue(string xmlPath,string AppKey,ref string AppValue)//读xmlPath是文件路径+文件名,AppKey是 Key Name,AppValue是Value
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlPath);
XmlNode xNode;
XmlElement xElem1;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if ( xElem1 != null )
{
AppValue=xElem1.GetAttribute ("value");
}
else
{
// MessageBox.Show ("There is not any information!");
}
}
#endregion
关键词:xml
相关阅读
- 03-06Windows 7下找不到msxml.dll的错误的解决方法
- 04-09Win7系统 msxml3.dll的问题!及解决方法!
- 02-26xml文件如何打开?怎样打开XML文件?
- 02-16ASP中查询数据库记录写入XML文件示例
- 02-16xmlhttp组件获取远程文件并筛选出目标数据
- 02-16利用XMLHTTP 从其他页面获取数据
- 02-16XML的严格格式
- 02-16XML入门精解之结构与语法
- 02-16用XML和XSL来生成动态页面
阅读本文后您有什么感想? 已有 人给出评价!
用户评论
热门评论
最新评论
相关软件
热点图文
- 02-16XML Schema学习笔记
- 06-14什么是 XML Web Service
- 02-16XML入门精解之结构与语法
- 06-19XML文档的基本操作
- 02-16ASP中查询数据库记录写入XML文件示例
- 02-16用XML和XSL来生成动态页面
- 02-07读写xml文件的2个小函数
- 02-16XML、Web服务和.NET框架
- 02-16XML的严格格式
- 06-13什么是XML