parsing XML content - C#

前端 未结 6 1596
轮回少年
轮回少年 2021-01-21 00:40

I have not used XML for very long and need to extract the useful information from an XML response. If there are 2 tags that are the same but have a different name e.g



        
6条回答
  •  遇见更好的自我
    2021-01-21 01:10

    You may use the System.Xml.Linq namespace:

    var xDoc = XDocument.Parse(xml);
    var result = xDoc.Descendants()
        .Where(d => 
            d.Name == "lst" && 
            d.Attributes("name").FirstOrDefault()!=null &&
            d.Attributes("name").FirstOrDefault().Value == "overflow")
        .FirstOrDefault();
    

提交回复
热议问题