,我有以下XML數據:查詢在XML decendants到LINQ
<portfolio>
<item>
<title>Site</title>
<description>Site.com is a </description>
<url>http://www.site.com</url>
<photos>
<photo url="http://www.site.com/site/thumbnail.png" thumbnail="true" description="Main" />
<photo url="http://www.site.com/site/1.png" thumbnail="false" description="Main" />
</photos>
</item>
</portfolio>
在C#中,我使用以下鏈接查詢:
List<PortfolioItem> list = new List<PortfolioItem>();
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("~/app_data/portfolio.xml"));
list = (from portfolio in xmlDoc.Descendants("item")
select new PortfolioItem()
{
Title = portfolio.Element("title").Value,
Description = portfolio.Element("description").Value,
Url = portfolio.Element("url").Value
}).ToList();
如何去查詢照片的節點?在PortfolioItem類我有一個屬性:
List<Photo> Photos {get;set;}
任何想法,將不勝感激!