码迷,mamicode.com
首页 > 其他好文 > 详细

xml保存基本信息

时间:2015-10-29 12:47:56      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

        public static string getXML(string nodeName)
        {
            string strReturn = "";
            try
            {
                string fileName = Application.StartupPath;
                string strFile = fileName + @"\Info.xml";
                if (File.Exists(strFile))
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.Load(strFile);
                    try
                    {
                        //根据路径获取节点
                        XmlNode xmlNode = null;
                        xmlNode = xdoc.SelectSingleNode("PowerConfig/" + nodeName);
                        strReturn = xmlNode.InnerText;
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show("配置文件异常!");
                    }
                }
                else
                {
                    MessageBox.Show("文件有误!请检查确认!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取配置异常!" + ex.Message);
            }
            return strReturn;
        }
        public static void setXML(string nodeName, string value)
        {
            try
            {
                string fileName = Application.StartupPath;
                string strFile = fileName + @"\Info.xml";
                if (File.Exists(strFile))
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.Load(strFile);
                    try
                    {
                        xdoc.SelectSingleNode("PowerConfig/" + nodeName).InnerText = value;
                        xdoc.Save(strFile);

                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message);
                    }
                }
                else
                {
                    MessageBox.Show("文件有误!请检查确认!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取配置异常!" + ex.Message);
            }
        }

 

xml保存基本信息

标签:

原文地址:http://www.cnblogs.com/zhongxinWang/p/4919881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!