6

How to loop through all XElement attributes and get their values?

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

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

Thank you!

NoWar
  • 36,338
  • 80
  • 323
  • 498

2 Answers2

12

Simple - use the Attributes() method:

foreach (var attribute in element.Attributes())
{
    string value = attribute.Value;
    // ...
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

Assuming you want an answer to this question

var img2 = feeds.Items
     .SelectMany(i => i.ElementExtensions
                       .Select(e => e.GetObject<XElement>().Attribute("url").Value)
                )
     .ToArray();
Community
  • 1
  • 1
L.B
  • 114,136
  • 19
  • 178
  • 224