How to iterate over all XElement attributes and get their values

How to skip 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? } 

Thanks!

+6
source share
2 answers

Simple - use the Attributes() method:

 foreach (var attribute in element.Attributes()) { string value = attribute.Value; // ... } 
+9
source

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(); 
+2
source

Source: https://habr.com/ru/post/915431/


All Articles