获取XML中的所有属性

Abb*_*bas 2 c# xml

我有这样的XML:

<msg action="getDetails" class="2">
   <stamps msgtime="4/15/2014" ltq="2014-04-15">
       <dat la="get" />
   </stamps>
</msg>
Run Code Online (Sandbox Code Playgroud)

如何检索所有属性及其相应值的字典?预期的输出应该是这样的:

action - getDetails
class - 2
msgtime -
4/15/2014 ltq - 2014-04-15
la - get

我可以让它适用于特定级别,但不适用于所有子元素.

Sel*_*enç 6

var xDoc = XDocument.Load("path");

var attributes = xDoc.Descendants()
                 .SelectMany(x => x.Attributes())
                 .ToDictionary(x => x.Name.LocalName, x => (string)x);
Run Code Online (Sandbox Code Playgroud)