<item>
<title>Lorem Ipsum</title>
<media:group>
<media:content url = "http://www.sample.com" rate = "0" />
<media:content url = "http://www.sample1.com" rate = "1" />
<media:content url = "http://www.sample2.com" rate = "2" />
</media:group>
</item>
我如何获得此值:
我尝试使用此代码:
var query = from i in loadedData.Descendants("item")
select new Site
{
Title = (string)i.Element("title"),
Url = (string)i.Element(serv + "group").Elements(media + "content").Last()
};
site = query.ToList();
但是Url的值是&#34;&#34;。 我也有这个:
private static readonly XNamespace media = "http://www.sampleX.com/";
答案 0 :(得分:0)
您可以使用此LINQ查询:
var list = loadedData.Descendants("item")
.Select(e => new Site()
{
Title = e.Element("title")
.Value,
Url = e.Descendants(media + "content")
.Last()
.Attribute("url")
.Value
})
.ToList();