手机
当前位置:查字典教程网 >编程开发 >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个小函数】相关文章:

xml文件的结构解读第1/2页

XML、DataSet、DataGrid结合一

一个用xslt样式将xml解析为xhtml的类TransformBinder(兼容FF和IE7.0)

UTF8转成GB2312乱码问题解决方案

WAP建站WML语言语法基础教程第1/6页

使用xmldom在服务器端生成静态html页面

XML入门的常见问题(二)

asp下利用xml打包网站文件

用xslt将xml解析成xhtml的代码

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

精品推荐
分类导航