关于节点位置和属性值的XPath查询

bit*_*onk 0 xpath xpathdocument

有没有办法构建一个XPath查询,在某个位置找到一个节点并具有某个属性值?

请考虑以下示例xml:

<Item Type="Book">
<!--1st Param node in a Book item is always the autors last name-->
<Param Value="Updike" />
<!--2nd Param node in a Book item is always the autors first name-->
<Param Value="John" />
<!--3rd Param node in a Book item is always the book title-->
<Param Value="Toward the End of Time" /></Item>
Run Code Online (Sandbox Code Playgroud)

现在我可以构建一个查找以下内容的查询:

找到所有项目的节点类型,其中第2个"书" 帕拉姆节点都有一个 "约翰"的.所以我想找到作者名字的所有书籍都是"约翰".

请注意,我使用的是.NET XPathDocument.

小智 5

只有作为书籍的项目的要求怎么样?

试试这个:

/Item[@Type='Book'][Param[2][@Value='John']]
Run Code Online (Sandbox Code Playgroud)