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);
}
}