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>
{
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>