在项目中遇到对xml的操作,以前对这方面不太熟,最后在网上看了参考了一下资料,下面是自己写的一个操作xml的类,包含基本的增,删,改,查操作。
下面是xml文件的内容:
///
<copyright>
青岛英网咨询技术有限公司1999-2007
</copyright>
/// <version> 1.0 </version>
/// <author> zhangl </author>
/// <email> zhangl@hrbanlv.com </email>
/// <logdate="2007-08-06"> 创建 </log>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Data.SqlClient;
/// <summary>
/// XmlOperate的摘要说明
/// </summary>
public class XmlOperate
{
private string datafile = "" ;
private string id = "" ;
private string dbname = "" ;
private string backdate = "" ;
public string DataFile
{
set {
datafile = value;
}
}
public string ID
{
set
{
id = value;
}
}
public string DbName
{
set
{
dbname = value;
}
}
public string BackDate
{
set
{
backdate = value;
}
}
/// <summary>
/// 构造函数
/// </summary>
public XmlOperate()
{
}
/// <summary>
/// 构造带参数的构造函数
/// </summary>
/// <paramname="strdbname"></param>
/// <paramname="strbackdate"></param>
///
public XmlOperate( string strid, string strdbname, string strbackdate)
{
this .id = strid;
this .dbname = strdbname;
this .backdate = strbackdate;
}
读xml操作
写xml操作
删除xml节点操作
}
/// <version> 1.0 </version>
/// <author> zhangl </author>
/// <email> zhangl@hrbanlv.com </email>
/// <logdate="2007-08-06"> 创建 </log>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Data.SqlClient;
/// <summary>
/// XmlOperate的摘要说明
/// </summary>
public class XmlOperate
{
private string datafile = "" ;
private string id = "" ;
private string dbname = "" ;
private string backdate = "" ;
public string DataFile
{
set {
datafile = value;
}
}
public string ID
{
set
{
id = value;
}
}
public string DbName
{
set
{
dbname = value;
}
}
public string BackDate
{
set
{
backdate = value;
}
}
/// <summary>
/// 构造函数
/// </summary>
public XmlOperate()
{
}
/// <summary>
/// 构造带参数的构造函数
/// </summary>
/// <paramname="strdbname"></param>
/// <paramname="strbackdate"></param>
///
public XmlOperate( string strid, string strdbname, string strbackdate)
{
this .id = strid;
this .dbname = strdbname;
this .backdate = strbackdate;
}
读xml操作
写xml操作
删除xml节点操作
}
下面是xml文件的内容:
<?
xmlversion="1.0"encoding="utf-8"
?>
< baks >
< bak >
< id > 1 </ id >
< dbname > ehrdb_db_2007080713420096.BAK </ dbname >
< backdate > 2007.08.07 </ backdate >
</ bak >
< bak >
< id > 2 </ id >
< dbname > ehrdb_db_2007080713402905.BAK </ dbname >
< backdate > 2007.08.07 </ backdate >
</ bak >
</ baks >
< baks >
< bak >
< id > 1 </ id >
< dbname > ehrdb_db_2007080713420096.BAK </ dbname >
< backdate > 2007.08.07 </ backdate >
</ bak >
< bak >
< id > 2 </ id >
< dbname > ehrdb_db_2007080713402905.BAK </ dbname >
< backdate > 2007.08.07 </ backdate >
</ bak >
</ baks >