Xpath 尝试查找具有命名属性的元素

Xpath 尝试查找具有命名属性的元素,xpath,Xpath,我试图在包含特定属性的文档中查找节点中的所有元素 节点本身包含如下内容 <chapter id="1561" parent="6542"> <name>Quiz</name> <action id="5520" parent="1561" on="show"> <name>on show hide nav_buttons</name> <actionitem actiontaken="hide"

我试图在包含特定属性的文档中查找节点中的所有元素

节点本身包含如下内容

<chapter id="1561" parent="6542">
  <name>Quiz</name>
  <action id="5520" parent="1561" on="show">
    <name>on show hide nav_buttons</name>
    <actionitem actiontaken="hide" target="object" targetobject="5518">
    </actionitem>
  </action>
  <action id="5517" parent="1561" on="show">
    <name>on show reset test for resitting</name>
    <actionitem actiontaken="resettest" target="object" targetobject="1689">
    </actionitem>
  </action>
  <button id="5439" parent="1561" resource="5440" ontop="true" proportional="true" mouseoverimage="5442" clickedimage="5441">
    <name>start_quiz_button</name>
  </button>
  <image id="6549" parent="1561" resource="6550" visible="false" proportional="false">
    <name>Rectangle to hide text (if required)</name>
  </image>
</chapter>
我没有找到targetobject的命中率,但它找到了资源。如果我使用//,那么它可以工作,但这会得到文档中的所有匹配项


我猜这是因为资源位于第一个子级,而targetobject不是,所以我如何才能仅在我想要的子节点上执行此操作?

您确切期望的结果是什么?如果只希望节点
章节
中包含属性targetobject的元素。您可以执行
//chapter//*[@targetobject]
您使用什么处理器或在什么环境下使用<代码>*[@targetobject]如果您是正确的元素,则应该给您两次点击。否则,您可能需要使用
/*[@targetobject]
或将其限制为某个已知的父元素。顺便说一下,您也可以通过
*[@targetobject或@resource]
在一个查询中同时获得这两个元素。这个元素是大型文档中许多章节中的一个。我所期望的是targetobject的命中率为2,但在xpath evaluate语句中使用节点时,*[@targetobject]的命中率为零。如果使用//,它会查找所有targetobject元素,而不管它们在文档中的位置如何,也就是在所有其他章节中,我不知道如何防止这种情况。我发现使用后代::*[@targetobject]可以在特定章节的后代中定位某些内容。
*[@targetobject]
*[@resource]