how to get matchClock data using linq in xml RRS feed


  • User36583972 posted

    Hi progy85,

    From your description, you want to get the information you want from the node in the XML. You should make sure your XML format is correct. I have made a sample on my side, I can read the node information (if the structure is complex, you can nested query). The following code in my project for your reference.


    <?xml version="1.0" encoding="utf-8"?>
      <Employee type="Permanent">
      <Employee type="Temporary">
      <Employee type="Permamnet">
      <Employee type="Temporary">


    protected void Button2_Click(object sender, EventArgs e)
                string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+ "test.xml";
                XElement xe = XElement.Load(str);
                IEnumerable<XElement> elements = from ele in xe.Elements("Employee")
                                                 select ele;
            private void showInfoByElements(IEnumerable<XElement> elements)
                List<Employee> modelList = new List<Employee>();
                foreach (var ele in elements)
                    Employee model = new Employee();
                    model.type = ele.Attribute("type").Value;
                    model.ID = ele.Element("ID").Value;
                    model.FirstName = ele.Element("FirstName").Value;
                    model.LastName = ele.Element("LastName").Value;
                    model.Dept = ele.Element("Dept").Value;
                GridView1.DataSource = modelList;
                Response.Write("Count Nodes:"+modelList.Count.ToString());

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 9, 2016 8:07 AM