ASP.NET读写XML文件的示例代码
2013-08-31 19:24
501 查看
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("//www.tydsyy.comappSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if ( xElem1 != null )
{
AppValue=xElem1.GetAttribute ("value");
}
else
{
// MessageBox.Show ("There is not any information!");
}
}
#endregion
{
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("//www.tydsyy.comappSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if ( xElem1 != null )
{
AppValue=xElem1.GetAttribute ("value");
}
else
{
// MessageBox.Show ("There is not any information!");
}
}
#endregion
相关文章推荐
- asp.net 读写xml文件示例代码
- 一个ASP.NET读写XML文件的示例
- ASP.NET读写XML文件的示例
- c#/ASP.NET操作cookie(读写)代码示例
- ASP.NET中读写cookie数据示例代码
- ASP.NET中读写cookie数据示例代码
- asp.net读写添加修改删除操作xml文件 代码如下(C#)
- asp.net读写添加修改删除操作xml文件 代码如下(C#)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- ASP.NET 2.0 HttpHandler实现生成图片验证码(示例代码下载)
- Asp.net 2.0 自定义控件开发[创建自定义HeaderRow的GridView控件][示例代码下载]
- ASP.NET 2.0 HttpHandler实现生成图片验证码(示例代码下载)
- asp.net 对xml文件的读写,添加,修改,删除操作 .
- ASP.net的地址重写(URLRewriter)实现原理及代码示例
- JavaScript组件之JQuery(A~Z)教程(基于Asp.net运行环境)[示例代码下载]
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- ASP.NET 2.0 HttpHandler实现生成图片验证码(示例代码下载)
- Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]