WinForm编程之XML读写

这篇博客分享了在WinForm应用中进行XML文件读写的具体实例,探讨了如何高效处理XML数据并关注性能问题。文章提供了详细的代码示例。
摘要由CSDN通过智能技术生成
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个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值