考虑以下带有重复跟随兄弟的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)显然,重复的兄弟姐妹被视为重复......? 那么如何实现“给我第三个成功兄弟”的效果呢?
谢谢!
Consider the following xpath with repeated following-sibling's:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)It has the same result as a single following-sibling:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)Apparently the repeated following-sibling's are treated as duplicates ..? So then how to achieve the effect of "give me the third succeeding sibling" ?
thanks!
最满意答案
给出以下XML:
<tr> <td>Map</td> <td>First</td> <td>Second</td> <td>Third</td> </tr>这些XPath(第二个建议来自@paul t。)
//tr/td[text()='Map']/following-sibling::td[3]/text() //tr[td='Map']/td[4]/text()按预期返回'Third' 。
Given the following XML:
<tr> <td>Map</td> <td>First</td> <td>Second</td> <td>Third</td> </tr>these XPaths (second by suggestion from @paul t.)
//tr/td[text()='Map']/following-sibling::td[3]/text() //tr[td='Map']/td[4]/text()return 'Third' as expected.
如何从xpath实现多个follow-sibling(How to achieve multiple following-sibling's from an xpath)考虑以下带有重复跟随兄弟的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)显然,重复的兄弟姐妹被视为重复......? 那么如何实现“给我第三个成功兄弟”的效果呢?
谢谢!
Consider the following xpath with repeated following-sibling's:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)It has the same result as a single following-sibling:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)Apparently the repeated following-sibling's are treated as duplicates ..? So then how to achieve the effect of "give me the third succeeding sibling" ?
thanks!
最满意答案
给出以下XML:
<tr> <td>Map</td> <td>First</td> <td>Second</td> <td>Third</td> </tr>这些XPath(第二个建议来自@paul t。)
//tr/td[text()='Map']/following-sibling::td[3]/text() //tr[td='Map']/td[4]/text()按预期返回'Third' 。
Given the following XML:
<tr> <td>Map</td> <td>First</td> <td>Second</td> <td>Third</td> </tr>these XPaths (second by suggestion from @paul t.)
//tr/td[text()='Map']/following-sibling::td[3]/text() //tr[td='Map']/td[4]/text()return 'Third' as expected.
发布评论