我如何在Form Load上验证XML文件? (XML文件为空)
private void Form1_Load(object sender, EventArgs e)
{
// --------------- Read XML File / Data: Settings_General
String xmlfile = "Settings_General.xml";
XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);
XmlNode comboBox4Value = doc.SelectSingleNode("XMLFILE/Active");
if (comboBox4Value != null)
{
comboBox4.SelectedIndex = Convert.ToInt32(comboBox4Value.InnerText);
}
}
答案 0 :(得分:0)
如果xml格式无效,则doc.Load(xmlfile);
将抛出异常。