【发布时间】:2013-08-23 21:06:55
【问题描述】:
我开始用 C# 编程,我是初学者,所以我没有经验。我想有一天成为一名专业人士并开始开发解决方案。我的程序将信息保存在 xml 文件中,然后在相同的 xml 中读取相同的信息。 xml文件有这种格式
<Dados>
<Nome>Vitor Emanuel Macedo Ferreira</Nome>
<Sexo>M</Sexo>
<Idade>22</Idade>
<Peso>86</Peso>
<Altura>1.87</Altura>
</Dados>
在 C# 代码中,我的解决方案有:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML|*.xml";
ofd.FileName = ("c:\\xml\\data.xml");
if (ofd.ShowDialog() == DialogResult.OK)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(ofd.FileName);
xDoc.SelectSingleNode("Dados");
if (ofd.FileName == "c:\\xml\\data.xml" && xDoc.SelectSingleNode(string.Empty) == xDoc.SelectSingleNode("Dados"))
{
label8.Show();
textBox1.Hide();
textBox2.Hide();
textBox3.Hide();
radioButton1.Hide();
radioButton2.Hide();
label1.Hide();
label2.Hide();
label3.Hide();
label4.Hide();
label5.Hide();
}
else if (ofd.FileName == "c:\\xml\\data.xml" && xDoc.SelectSingleNode("") != xDoc.SelectSingleNode("Dados"))
{
MessageBox.Show("XML in incorrect path please put your xml file in c:\\xml");
}
}
如何过滤xml文件的内容,尤其是标签。我需要我的解决方案读取 xml 文件,当他读取标签时,他应该能够通过消息框说“错误标签不等于”,否则如果标签等于他必须继续
【问题讨论】:
标签: c# xml if-statement tags selectsinglenode