Converting XmlDocument to Dictionary

后端 未结 3 1454
长发绾君心
长发绾君心 2021-01-16 09:54

I\'m looking for a good way to convert an XmlDocument to Dictionary using Linq.

My xml is formatted like this:

<
3条回答
  •  野的像风
    2021-01-16 10:42

    I dont know if its the better way, but its clean & simple..

    XElement xdoc = XElement.Load("yourFilePath");
    Dictionary result = (from element in xdoc.Elements() select new KeyValuePair(element.Name.ToString(), element.Value)).ToDictionary(x => x.Key, x => x.Value);
    

提交回复
热议问题