第一次发表,尽请拍砖。。。

public class ConfigurationBase
    {
        protected static XmlDocument XmlDoc = null;
        private static string XmlPath = string.Empty;

        public ConfigurationBase()
        { }

        public ConfigurationBase(string xmlPath)
        {
            XmlDoc = new XmlDocument();
            XmlDoc.Load(xmlPath);
            XmlPath = xmlPath;
        }

        protected XmlNode Node(string nodeName)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}", nodeName));
        }

        protected XmlNode Node(string nodeName, string Attribute)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}[@{1}]", nodeName, Attribute));
        }

        protected XmlNode Node(string nodeName, string Attribute, string AttrValue)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}[@{1}='{2}']", nodeName, Attribute, AttrValue));
        }

        protected string AttrValue(string nodeName, string Attribute)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}", nodeName)).Attributes[Attribute].Value;
        }

        protected string NodeValue(string nodeName)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}", nodeName)).Value;
        }

        protected string NodeValue(string nodeName, string Attribute)
        {
            return XmlDoc.SelectSingleNode(string.Format("//{0}[@{1}]", nodeName, Attribute)).Value;
        }

        protected XmlNodeList NodeList(string nodeName)
        {
            return XmlDoc.SelectNodes(string.Format("//{0}", nodeName));
        }

        protected XmlNodeList NodeList(string nodeName, string Attribute)
        {
            return XmlDoc.SelectNodes(string.Format("//{1}[@{1}]", nodeName, Attribute));
        }

        protected bool UptNode(XmlNode node)
        {
            XmlDoc.AppendChild(node);
            XmlDoc.Save(XmlPath);
            return true;
        }

        protected bool UptNode()
        {
            XmlDoc.Save(XmlPath);
            return true;
        }

        protected static XmlDocument Document
        {
            set
            {
                XmlDoc = value;
            }
        }
    }

 

posted on 2011-04-28 13:20  wolfweb  阅读(242)  评论(0)    收藏  举报