教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 asp.net读写xml文件的代码一例

asp.net读写xml文件的代码一例

发布时间:2016-03-03   编辑:jiaochengji.com
asp.net操作xml文件的能力还是很强的,这里为大家介绍一个asp.net读写xml文件的代码,供大家学习参考。

代码如下:

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!");
   }
}//www.jbxue.com
#endregion

您可能感兴趣的文章:
C#读写xml文件的简单例子
C#读写xml配置文件(LINQ操作实例)
C#读写xml文件的实例代码

您可能感兴趣的文章:
asp.net读写xml文件的代码一例
php操作xml文件的一些简单范例
C#读写xml文件的简单例子
C#读写xml配置文件(LINQ操作实例)
C# 生成XML文档的三种方法与代码实例
php解析XML数据的一段代码
c# 解析XML文件的方法总结
C# 写入XML文档的三种方法与代码实例
PHP读取XML的几种方法
asp.net 自定义用户控件数据读取及赋值实例

[关闭]
~ ~