我正在XML文件中搜索两个元素(supportsA,supportsB)。
以下是两个存在的例子:
<ovw ...>
<supports>
<supportsA/>
<supportsB/>
</supports>
...
这是我在阅读了几篇关于SO的文章之后的尝试:
var vSupportsA = (from d in doc.Descendants()
where d.Name.LocalName == "supportsA"
select d.Value).First();
var vSupportsB = (from d in doc.Descendants()
where d.Name.LocalName == "supportsB"
select d.Value).First();
if (vSupportsA != null && vSupportsB != null) {
// supportsA *and* supportsB
}
else if (vSupportsA != null) {
// supportsA only
}
else if (vSupportsB != null) {
// supportsB only
}
else {
// neither element found
}
显然,我做错了,因为我收到一条错误,指出“Sequent不包含任何元素”。不幸的是,我不知道这意味着什么。