0

我如何验证表单加载上的 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);
    }
}
4

1 回答 1

0

If xml is in invalid format then doc.Load(xmlfile); will throw exception.

于 2012-08-28T06:34:13.847 回答