简体   繁体   中英

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."

exactly i have to get value sst5038 from the above xml file.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM