...
string param1;
string param2;
string param3;
bool flag1;
...
static class SaveAppSetting
{
{
public static string fname_xml = @"\appSetting.xml";
static XmlDocument doc;
static public void LoadXmlAppSetting()
{
if (System.IO.File.Exists(fname_xml))
{
doc = new XmlDocument();
doc.Load(fname_xml);
{
if (System.IO.File.Exists(fname_xml))
{
doc = new XmlDocument();
doc.Load(fname_xml);
param1 = getStringValue("/setting/equipment/param1");
param2 = getStringValue("/setting/equipment/param2");
param3 = getStringValue("/setting/equipment/param3");
flag1 = getBoolValue("/setting/dbg/log_7e1_codeString");
}
}
}
static public void SaveXmlAppSetting()
{
string xml_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<setting>";
xml_content += "<equipment>";
xml_content += "<param1>" + param1 + "</param1>";
xml_content += "<param2>" + param2 + "</param2>";
{
string xml_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<setting>";
xml_content += "<equipment>";
xml_content += "<param1>" + param1 + "</param1>";
xml_content += "<param2>" + param2 + "</param2>";
xml_content += "<param3>" + param3 + "</param3>";
xml_content += "<flag1>" + flag1.ToString() + "</flag1>";
xml_content += "</equipment>";
xml_content += "</setting>";
try
{
doc = new XmlDocument();
doc.LoadXml(xml_content);
doc.Save(fname_xml);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
xml_content += "</equipment>";
xml_content += "</setting>";
try
{
doc = new XmlDocument();
doc.LoadXml(xml_content);
doc.Save(fname_xml);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
static private string getStringValue(string xml_path, string default_value = "-")
{
string ret_value = "";
try
{
ret_value = doc.SelectSingleNode(xml_path).InnerText.Trim();
}
catch
{
ret_value = default_value;
}
{
ret_value = default_value;
}
return ret_value;
}
}
static private bool getBoolValue(string xml_path, bool default_value = false)
{
{
bool ret_value = false;
try
{
ret_value = Convert.ToBoolean(doc.SelectSingleNode(xml_path).
InnerText.Trim());
}
{
ret_value = Convert.ToBoolean(doc.SelectSingleNode(xml_path).
InnerText.Trim());
}
catch
{
ret_value = default_value;
}
{
ret_value = default_value;
}
return ret_value;
}
}
}
Комментариев нет:
Отправить комментарий