我有这样的XML
结果
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">16</int>
</lst>
<result name="response" numFound="3" start="0" maxScore="1.0">
<doc>
<str name="ContaFirstname">
firstname1
</str>
<str name="ContaId">6557</str>
<str name="ContaJobTitle">Manager</str>
<str name="ContaSurname">surname1
</str>
</doc>
<doc>
<str name="ContaFirstname">firstname2</str>
<str name="ContaId">6203</str>
<str name="ContaJobTitle">Director</str>
<str name="ContaSurname">surname2</str>
</doc>
</result>
</response>
我想得到一个对象列表,每个对象都包含ContaFirstname
,ContaId
和ContaJobTitle
ContaSurname
我尝试过这样的事情,但这是不对的,因为我把它们都设为 NULL
var test = from c in xml.Descendants("doc")
select new
{
firstname = c.Element("ContaFirstname"),
surnmane = c.Element("ContaSurname")
};
那么如何通过名称访问这些元素呢?