6

如何遍历所有 XElement 属性并获取它们的值?

foreach (SyndicationElementExtension extension in f.ElementExtensions)
{
    XElement element = extension.GetObject<XElement>();

    // How to loop through all its attributes and get their values?
}

谢谢!

4

2 回答 2

12

简单 - 使用Attributes()方法:

foreach (var attribute in element.Attributes())
{
    string value = attribute.Value;
    // ...
}
于 2012-05-10T18:29:23.507 回答
3

假设你想要这个问题的答案

var img2 = feeds.Items
     .SelectMany(i => i.ElementExtensions
                       .Select(e => e.GetObject<XElement>().Attribute("url").Value)
                )
     .ToArray();
于 2012-05-10T18:42:06.993 回答