[英]issue in get attribute name from xml file in wpf
I tried to get attribute of Chandru element but it showing the exception like "Exception has been thrown by the target of an invocation." 我试图获取Chandru元素的属性,但它显示了诸如“异常已被调用的目标抛出”的异常。
exactly i have to get value sst5038 from the above xml file. 正是我必须从上述xml文件中获取值sst5038。
Here the code what i wrote 这是我写的代码
public partial class XML_3 : Window
{
public XML_3()
{
this.InitializeComponent();
XmlDocument doc = new XmlDocument();
doc.Load("D:/student_2.xml");
XmlNodeList student_list = doc.GetElementsByTagName("Student");
foreach (XmlNode node in student_list)
{
XmlElement student = (XmlElement)node;
string sname = student.GetElementsByTagName("Chandru")[0].InnerText;
string fname = student.GetElementsByTagName("FName")[0].InnerText;
string id = student.Attributes["ID"].InnerText;
Window.Content = sname + fname + id;
}
}
}
please help me... 请帮我...
should be for first student 应该是第一个学生
string id = student.GetElementsByTagName("Chandru")[0].Attributes["ID"].InnerText;
and for second student 和第二个学生
string id = student.GetElementsByTagName("Guna")[0].Attributes["ID"].InnerText;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.