且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用linq to xml选择具有给定属性的元素

更新时间:2023-01-17 18:54:01

知道如何就很简单!

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.