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!");
   }

  }

  #endregion

时间: 2024-08-04 05:07:14

ASP.NET读写XML文件的示例代码的相关文章

ASP.NET中读取修改删除XML文件一些示例

ASP.NET读取XML文件4种方法分析,需要的朋友可以参考下. 方法一 :使用XML控件 代码如下:  代码如下 复制代码 <% @ Page Language="C#"%> <html> <body> <h3><font face="Verdana">读取XML方法一</font></h3> <from runat=server> <asp:Xml id=&qu

读写xml文件的2个小函数_XML示例

要利用DOM 来存取XML 文件,你必须将XML 文件连结到HTML 网页上. #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.L

用C#读写XML文件

问题描述 1.用C#读写XML文件2.将XML文件显示在文字框或者表格中求代码,讲解··· 解决方案 解决方案二: 解决方案三: 谢谢····段子鹏解决方案四: 不是用linq,是C#···解决方案五: 读///<summary>///根据节点名称读取PersonalAccountSettings.xml中节点的InnerText值///</summary>///<paramname="nodeName">节点名称</param>///&

asp.net操作xml增删改示例分享

 这篇文章主要介绍了asp.net操作xml增删改示例,需要的朋友可以参考下   代码如下: using System;  using System.Collections;  using System.ComponentModel;  using System.Data;  using System.Drawing;  using System.Web;  using System.Web.SessionState;  using System.Web.UI;  using System.We

asp.net 读取xml文件里面的内容,绑定到dropdownlist中_实用技巧

xml文件编写 复制代码 代码如下: <?xml version="1.0" encoding="gb2312" ?> <BookType> <parameter> <name>商务管理</name> <value>0</value> </parameter> <parameter> <name>金融管理</name> <valu

asp.net创建XML文件的方法小结_实用技巧

本文实例讲述了asp.net创建XML文件的方法.分享给大家供大家参考,具体如下: 方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法二:直接定影XML文档,然后保存到文件. 通过"XmlDocumen

Vc 读写xml文件二个实例

vc 读写xml文件二个实例 <?xml version="1.0" encoding="gb2312"?>   <root> <device id="10041" name="设备1">   <type>13 </type>   <typename>保护 </typename>   </device>  </root>

读写xml文件的2个小函数

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 xNod

asp内置函数formatdatetime使用示例代码

asp内置函数formatdatetime使用示例代码 formatdatetime(now(),0) '则返回2004-10-18 11:45:53   formatdatetime(now(),1) '则返回2004年10月18日   formatdatetime(now(),2) '则返回2004-10-18   formatdatetime(now(),3) '则返回11:47:12   formatdatetime(now(),4) '则返回11:47   weekDayName(we