Select element with given attribute using linq to xml

前端 未结 2 1721
萌比男神i
萌比男神i 2020-12-11 07:06

I\'ve got following XML structure:


     
         
                  


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 07:57

    It's quite simple when you know how!

    var artistsAndImage = from a in feed.Descendants("artist")
                          from img in a.Elements("image")
                          where img.Attribute("size").Value == "big"
                          select new { Name = a.Element("Name").Value
                                     , Image = img.Value};
    

    This will return all the names and big images for all the artists.

提交回复
热议问题