1.界面:
2.选项文件按钮:
/// <summary>
/// 选择文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
//初始化一个OpenFileDialog类
OpenFileDialog fileDialog = new OpenFileDialog();
//判断用户是否正确的选择了文件
if (fileDialog.ShowDialog() == DialogResult.OK)
{
//获取用户选择文件的后缀名
string extension = Path.GetFullPath(fileDialog.FileName);
this.textBox1.Text = extension;
MessageBox.Show(extension);
}
}
3.查询按钮
/// <summary>
/// 查询按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
#region 1
XmlDocument xmldoc = new XmlDocument();
try
{
xmldoc.Load(textBox1.Text);
//获取节点列表
//得到顶层节点列表
XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
foreach (XmlNode xn in topM)
{
XmlElement element = xn as XmlElement;//最好不好用强制转换,建议使用as,这样如果转不过去话,就是null,不会报异常
if (element != null)
{//这样判断以下是否为null,或者你可以if(xe=