How can I get single node data using linq

后端 未结 5 954
生来不讨喜
生来不讨喜 2021-01-29 09:27

I have the following xml file


  
    1
    Computer
    Infor         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 09:33

    You can use LINQ to XML like

    XDocument xDoc = XDocument.Load("test.XML");
    var item = xDoc.Descendants("category")
                   .FirstOrDefault(r => r.Element("id").Value == "1");
    if(item == null)
       return;
    
    string Name = item.Element("name").Value;
    string Decription = item.Element("description").Value;
    string active = item.Element("active").Value;
    

    You can assign the results to your TextBoxes as per your requirement.

提交回复
热议问题