且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#中的LINQ to XML - 的XDocument

更新时间:2022-06-26 04:46:34

您需要通过名字从XML以检索后代节点。同时ACCOUNTNAME和电子邮件不是一个属性,它的XML的元素。属性是内部因素。

You need to retrive Descendants node by name from xml. Also "accountname" and "email" is not an attributes, its an Element of XML. Attributes are inside element.

替换您的查询

 var query = xml.Descendants("configaccount")
        .Select(o => new OperationConfig
        {
            AccountName = o.Element("accountname").Value,
            Email = o.Element("email").Value
        });



希望这有助于

Hope this help