1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10 using System.Collections;
11
12 // 引用命名空间
13 using System.Xml;
14
16 namespace xmlOp
17 {
18 /// <summary>
19 /// XmlOp类提供对XML数据库的读写
20 /// </summary>
21
public
class
XmlOp
22 {
23
//
声明一个XmlDocument空对象
24
protected
XmlDocument XmlDoc
=
new
XmlDocument();
25
26
///
<summary>
27
///
构造函数,导入Xml文件
28
///
</summary>
29
///
<param name="xmlFile">
文件虚拟路径
</param>
30
public
XmlOp(
string
xmlFile)
31 {
32
try
33 {
34
XmlDoc.Load(GetXmlFilePath(xmlFile));
//
载入Xml文档
35 }
36
catch
(System.Exception ex)
37 {
38
throw
ex;
39 }
40
}
41
///
<summary>
42
///
析构函数
43
///
</summary>
44
~
XmlOp()
45 {
46
XmlDoc
=
null
;
//
释放XmlDocument对象
47 }
48
49
///
<summary>
50
///
保存文件
51
///
</summary>
52
///
<param name="filePath">
文件虚拟路径
</param>
53
public
void
Save(
string
filePath)
54 {
55
try
56 {
57
XmlDoc.Save(GetXmlFilePath(filePath));
58
}
59
catch
(System.Exception ex)
60 {
61
throw
ex;
62 }
63
}
64
65
///
<summary>
66
///
返回Xml文件实际路径
67
///
</summary>
68
///
<param name="xmlFile">
文件虚拟路径
</param>
69
///
<returns></returns>
70
public
string
GetXmlFilePath(
string
xmlFile)
71 {
72
return
HttpContext.Current.Server.MapPath(xmlFile);
73 }
74
75
///
<summary>
76
///
根据Xml文件的节点路径,返回一个DataSet数据集
77
///
</summary>
78
///
<param name="XmlPathNode">
Xml文件的某个节点
</param>
79
///
<returns></returns>
80
public
DataSet GetDs(
string
XmlPathNode)
81 {
82
DataSet ds
=
new
DataSet();
83
try
84 <
10 using System.Collections;
11
12 // 引用命名空间
13 using System.Xml;
14
16 namespace xmlOp
17 {
18 /// <summary>
19 /// XmlOp类提供对XML数据库的读写
20 /// </summary>
21
22
24
25
26
27
28
29
30
31
33
35
37
39
42
43
44
45
47
49
50
51
52
53
54
56
60
62
65
66
67
68
69
70
71
73
75
76
77
78
79
80
81
83
84