我正在尝试解析以下 XML:
<bs:School>
<bs:Class number="1">
<bs:Student>
<bs:Gender>Male</bs:Gender>
<bs:Name>Jason</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Male</bs:Gender>
<bs:Name>Danny</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Female</bs:Gender>
<bs:Name>Jessica</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Male</bs:Gender>
<bs:Name>Will</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Female</bs:Gender>
<bs:Name>Betty</bs:Name>
</bs:Student>
</bs:Class>
<bs:Class number="2">
<bs:Student>
<bs:Gender>Male</bs:Gender>
<bs:Name>Sean</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Female</bs:Gender>
<bs:Name>Jessica</bs:Name>
</bs:Student>
<bs:Student>
<bs:Gender>Male</bs:Gender>
<bs:Name>Dexter</bs:Name>
</bs:Student>
</bs:Class>
</bs:School>
如何选择所有男学生的名字?
我尝试使用以下 LINQ 查询:
var resources = from c in doc.Descendants("Gender")
where (c.Value.ToString().Contains("Male"))
select c.Parent.Descendants("Name");
它总是返回一个空对象。