我一直在寻找具有以下结构的 xml 的 Xpath....
<abc>
<unique>
<findme uniqueAtrr="itsme">Already Found Xpath For This</findme>
</unique>
<findme></findme>
<findme></findme>
<findme uniqueAtrr="itsme"> You Got Me</findme> //NOTE : We don't know this position
<findme></findme>
</abc>
我使用“Already Found”获得了 XPath
/abc//unique/findme[@uniqueAtrr="itsme"]
所以我认为找到的最好方法是搜索 findme,它在唯一标签中不存在...或者仅在 sibling 中查找节点...我尝试过的那个。 ..
/abc//findme
这将为我提供唯一标签内的一个:(
最佳答案
尝试下面的 xpath 来匹配 “You Got Me”
:
/abc/unique/following-sibling::findme[@uniqueAtrr="itsme"]
关于java - 如何使用Xpath java仅在 sibling 中查找节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45532088/