0

考虑以下带有重复跟随兄弟的 xpath:

//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)

它与单个跟随兄弟的结果相同:

//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)

显然重复的后续兄弟姐妹被视为重复..?那么如何达到“给我第三个兄弟姐妹”的效果呢?

谢谢!

4

1 回答 1

0

给定以下 XML:

<tr>
    <td>Map</td>
    <td>First</td>
    <td>Second</td>
    <td>Third</td>
</tr>

这些 XPaths(第二个来自 @paul t 的建议。)

//tr/td[text()='Map']/following-sibling::td[3]/text()
//tr[td='Map']/td[4]/text()

'Third'按预期返回。

于 2013-10-22T22:00:44.873 回答