我需要找到具有属性 nodeName="Industries" 的 SectionIndex,然后获取该 SectionIndex 中每个 Textpage 元素的属性(id 和 nodeName)
<SectionIndex nodeName="Industries">
<Textpage id="1" nodeName="Aerospace"</Textpage>
<Textpage id="2" nodeName="Construction"</Textpage>
<Textpage id="3" nodeName="Engineering"</Textpage>
</SectionIndex>
<SectionIndex nodeName="Greetings">
<Textpage id="1" nodeName="Hello"</Textpage>
<Textpage id="2" nodeName="GoodBye"</Textpage>
<Textpage id="3" nodeName="Later"</Textpage>
</SectionIndex>
我的查询看起来像
var queryServices = from s in xmldoc.Root.Descendants("SectionIndex")
where s.Attribute("nodeName").Value == "Industries"
select new
{
ServicesKey = s.Element("umbTextpage").Attribute("id").Value ?? "",
NodeName = s.Element("umbTextpage").Attribute("nodeName").Value ?? ""
};
它只返回航空航天。任何提示都会很棒。