我有这个XML文件:
<tree>
<grand name ="tom" id="1" sex="m" status="d" child="2" father="" />
<grand name="adam" id="11" sex="m" status="d" child="1" father="1" />
<grand name="john" id="111" sex="m" status="d" child="1" father="11" />
<grand name="pierre" id="1111" sex="m" status="d" child="3" father="111" />
<grand name="jan" id="11111" sex="f" status="d" child="" father="1111" />
<grand name="marc" id="11112" sex="m" status="d" child="" father="1111" />
</tree>
我尝试此代码仅在加载表单时显示第一个节点的属性:
private void Form1_Load(object sender, EventArgs e)
{
XmlDocument XDoc = new XmlDocument();
XDoc.Load("F:\\tree.xml");
XmlNode att = XDoc.SelectSingleNode("//grand/@name");
string nam = att.ToString();
label1.Text = att;
}
但我一无所获。
非常感谢。