将最美的计算机软件奉献给社会

博客园 首页 新随笔 联系 订阅 管理
private static string ReadNodeValue(string nodeName)
        {

            XmlDocument MyXml = new XmlDocument();

            string appPath = System.Windows.Forms.Application.StartupPath;

            string xmlPath = appPath.Substring(0, appPath.IndexOf("UI") + 2) + "\\" + "BackupSetting.xml";

            MyXml.Load(xmlPath);

            //MyXml.Load(@"D:\workfold\NTU3\code\workstation\UI\BackupSetting.xml");
            
            string nodeValue = string.Empty;

            XmlNodeList MyNodeList = MyXml.SelectSingleNode("bakSQL").ChildNodes;

            foreach (XmlNode MyNode in MyNodeList)
            {
                if (MyNode.Name == nodeName)
                {
                    nodeValue = MyNode.InnerText.Trim();
                    break;
                }
            }

            return nodeValue;
       
}

       private static void SetNodeValue(string nodeName, string nodeValue)
        {

            XmlDocument MyXml = new XmlDocument();

            string appPath = System.Windows.Forms.Application.StartupPath;

            string xmlPath = appPath.Substring(0, appPath.IndexOf("UI") + 2) + "\\" + "BackupSetting.xml";

            MyXml.Load(xmlPath);

            //MyXml.Load(@"D:\workfold\NTU3\code\workstation\UI\BackupSetting.xml");
 
            XmlNodeList MyNodeList = MyXml.SelectSingleNode("bakSQL").ChildNodes;

            foreach (XmlNode MyNode in MyNodeList)
            {
                if (MyNode.Name == nodeName)
                {
                    MyNode.InnerText = nodeValue;
                    break;
                }
            }

            MyXml.Save(xmlPath);
        }


**************************demo xml file*************************

<?xml version="1.0" encoding="utf-8"?>
<bakSQL>
  <dayBakStartHour>15</dayBakStartHour>
  <weekBakStartHour>
  </weekBakStartHour>
  <weekday>
  </weekday>
  <bakType>day</bakType>
  <interval>3600000</interval>
</bakSQL>
posted on 2010-09-25 17:34  赖顺生  阅读(4876)  评论(0编辑  收藏  举报