c# 读改xml

class ServerUtils
    {
         private static ServerUtils _instance = new ServerUtils();
        public static ServerUtils getInstance()
        {
            return _instance;
        }
        XmlDocument doc = new XmlDocument();
       
        private string serverIp;
        private string typecode;
        public string getServerIp()
        {
            doc.Load("XMLFile1.xml");
            XmlNode node = doc.SelectSingleNode("tongbu/server_ip");
            serverIp = node.FirstChild.Value;
            return serverIp;
        }
        public string gettypecheck()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("XMLFile1.xml");
            XmlNode node = doc.SelectSingleNode("tongbu/type");
            typecode = node.FirstChild.Value;
            return typecode;
        }
        public void ModifServerIP(string str)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("XMLFile1.xml");
            XmlNode node = doc.SelectSingleNode("tongbu/server_ip");
            XmlElement xe = (XmlElement)node;
            xe.InnerText = str;
            doc.Save("XMLFile1.xml");
          
        }
        public void Modiftypecode(string str)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("XMLFile1.xml");
            XmlNode node = doc.SelectSingleNode("tongbu/type");
            XmlElement xe = (XmlElement)node;
            xe.InnerText = str;
            doc.Save("XMLFile1.xml");

        }
    }

posted @ 2012-05-29 20:07  刘振明  阅读(190)  评论(0)    收藏  举报