我当前的LINQ查询和示例XML如下所示.我想要做的是从email-addresses元素中选择主电子邮件地址到User.Email属性.
这里最简单的方法是什么?
当前Linq查询(User.Email当前为空):
var users = from response in xdoc.Descendants("response")
where response.Element("id") != null
select new User
{
Id = (string)response.Element("id"),
Name = (string)response.Element("full-name"),
Email = (string)response.Element("email-addresses"),
JobTitle = (string)response.Element("job-title"),
NetworkId = (string)response.Element("network-id"),
Type = (string)response.Element("type")
};
Run Code Online (Sandbox Code Playgroud)
示例XML:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<response>
<contact>
<phone-numbers/>
<im>
<provider></provider>
<username></username>
</im>
<email-addresses>
<email-address>
<type>primary</type>
<address>alice@domain.com</address>
</email-address>
</email-addresses>
</contact>
<job-title>Account Manager</job-title>
<type>user</type>
<expertise nil="true"></expertise>
<summary nil="true"></summary>
<kids-names nil="true"></kids-names>
<location nil="true"></location>
<guid nil="true"></guid>
<timezone>Eastern …Run Code Online (Sandbox Code Playgroud)