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

jstl 字符串处理函数

XSL简明教程

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

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

XSLT轻松入门第二章:XSLT的实例

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

用xslt将xml解析成xhtml的代码

asp下利用xml打包网站文件

读大数据量的XML文件的读取问题

关联数据入门——RDF应用

精品推荐
分类导航