c#winforms在Form Load上验证XML文件

时间:2012-08-28 06:30:12

标签: c# xml winforms file validation

我如何在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);
    }
}

1 个答案:

答案 0 :(得分:0)

如果xml格式无效,则doc.Load(xmlfile);将抛出异常。

相关问题