日期:2010-11-12  浏览次数:20411 次

一直想要写一个操作XML文件的类,今天在网上找了一下,找到一个已写的差不多的类,对其进行扩展与修改,最终成了以下代码,供新手参考参考.
//
在此类中用到了XML事件.此类中对于节点的查找必需用xpath表达式,如果你对xpath表达式不了解可以查看我收藏的另外一篇文章:+XML文件操作:[学习xpath]XPath最通俗的教程+

  1using System;
  2using System.Xml;
  3using System.Web;
  4namespace solucky
  5{
  6    /**//// <summary>
  7    /// 必需用XPATH表达式来获取相应节点
  8    /// 关于xpath可以参见:
  9    /// </summary>
 10    public class MyXml
 11    {
 12        变量#region 变量
 13        /**//// <summary>
 14        /// xml文件所在路径类型
 15        /// </summary>
 16        /// <remarks>xml文件所在路径类型</remarks>
 17        public enum enumXmlPathType
 18        {   
 19            /**//// <summary>
 20            /// 绝对路径
 21            /// </summary>
 22            AbsolutePath,
 23            /**//// <summary>
 24            /// 虚拟路径
 25            /// </summary>
 26            VirtualPath
 27        }
 28
 29        private string xmlFilePath ;
 30        private enumXmlPathType xmlFilePathType ;
 31        private XmlDocument xmlDoc = new XmlDocument() ;
 32        #endregion
 33
 34
 35        属性#region 属性
 36        /**//// <summary>
 37        /// 文件路径
 38        /// </summary>
 39        /// <remarks>文件路径</remarks>
 40        public string XmlFilePath
 41        {
 42            get
 43            {
 44                return this.xmlFilePath;
 45            }
 46            set
 47            {
 48                xmlFilePath = value ;
 49
 50            }
 51        }
 52
 53        /**//// <summary>
 54        /// 文件路径类型
 55        /// </summary>
 56     &nbs