模板酷站

电脑版
提示:原网页已由神马搜索转码, 内容由www.mb5u.com提供.

2个读写xml文件的小函数_Xml教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:新兴XML处理方法VTD-XML介绍序言 本文所提及的VTD-XML并非本文作者原创,作者只是对它进行介绍。 问题 通常当我们提起XML的使用时,最头痛的部分便是XML的verbosity与XML的解析速度,当需要处理大XML文件时这个问题

#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实现多渠道接入网站的构架一.背景在现在的网站中,接入的渠道是越来越多了,技术也是越来越先进,WAP, SMS,EMAIL, 传统的Web, Socket等等,如果连数据库和LDAP也算接入的话,那在设计之中需要扩展的空间要做到很好 很好

来源:模板无忧/所属分类:Xml教程/更新时间:2009-05-18
最新评论:

暂时还没人评论! 快来抢沙发啊!


匿名评论
相关Xml教程