手机
当前位置:查字典教程网 >编程开发 >XML/RSS >读写xml文件的2个小函数
读写xml文件的2个小函数
摘要:要利用DOM来存取XML文件,你必须将XML文件连结到HTML网页上。#region读写xml文件的2个小函数,200542byhycpub...

要利用DOM来存取XML文件,你必须将XML文件连结到HTML网页上。

#region读写xml文件的2个小函数,200542byhyc

publicvoidSetXmlFileValue(stringxmlPath,stringAppKey,stringAppValue)//写xmlPath是文件路径+文件名,AppKey是KeyName,AppValue是Value

{

XmlDocumentxDoc=newXmlDocument();

xDoc.Load(xmlPath);

XmlNodexNode;

XmlElementxElem1;

XmlElementxElem2;

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);

}

publicvoidGetXmlFileValue(stringxmlPath,stringAppKey,refstringAppValue)//读xmlPath是文件路径+文件名,AppKey是KeyName,AppValue是Value

{

XmlDocumentxDoc=newXmlDocument();

xDoc.Load(xmlPath);

XmlNodexNode;

XmlElementxElem1;

xNode=xDoc.SelectSingleNode("//appSettings");

xElem1=(XmlElement)xNode.SelectSingleNode("//add[@key='"+AppKey+"']");

if(xElem1!=null)

{

AppValue=xElem1.GetAttribute("value");

}

else

{

//MessageBox.Show("Thereisnotanyinformation!");

}

}

#endregion

【读写xml文件的2个小函数】相关文章:

用ASP+Access创建网站RSS格式内容摘要

jstl 字符串处理函数

XML轻松学习手册(3)XML的术语

用XML和XSL来生成动态页面

XML、DataSet、DataGrid结合一

气象 XML 数据源应用程序开发指南-内容目录

给你的asp+ac站点加rss功能

XHTML 1.0:标记新的开端

xml中的空格之完全解说

怎样打开XML文件?xml文件如何打开?

精品推荐
分类导航