C# – How to loop through all XElement attributes and get their values

cxmlxpath

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!

Best Answer

Simple - use the Attributes() method:

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