关于解析xml文件问题
以下程序为解析xml,使用XmlTextReader类进行解析,总是报错,请高手看看,怎么回事?总是在while (reader.Read())报错。OpenFileDialog xml_data = new OpenFileDialog();
xml_data.Multiselect = true;
xml_data.Filter = "*.xml|*.xml";
1.zip
(843.19 KB)
if (xml_data.ShowDialog() == DialogResult.OK)
{
progressBar1.Value = 0;
textBox_jd.Text = "进度:" + "0%";
string filepath;
NameTable table = new NameTable();
foreach (string filename in xml_data.FileNames)
{
try
{
FileInfo xmld = new FileInfo(filename);
filepath = xmld.FullName;
XmlTextReader reader = new XmlTextReader(filepath,table);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.LocalName== "sn")
{
listBox_status.Items.Add(reader.ReadString());
}
}
reader.Close();
MessageBox.Show("CC");
}
catch(Exception)
{
MessageBox.Show("导入数据异常");
}
}
}