How to convert XML to Dictionary

后端 未结 3 948
孤独总比滥情好
孤独总比滥情好 2021-01-03 23:42

I\'ve xml as following:



  Log In
  

        
3条回答
  •  无人及你
    2021-01-04 00:22

    XDocument xdoc = XDocument.Load("test.XML");
    var query = xdoc.Descendants("root")
                    .Elements()
                    .ToDictionary(r => r.Attribute("name").Value,
                                 r => r.Value);
    

    Remeber to include :

    using System.Linq;
    using System.Xml.Linq;
    

提交回复
热议问题