给出以下HTML:
<body>
<h2>
<span class="mw-headline" id="KNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&action=edit&section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
<div class="h"></div>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<h2>
<span class="mw-headline" id="NEXTKNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&action=edit&section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
</body>
我有ID="KNOWNID
&#34;并且需要选择所有<p></p>
元素,直到id="NEXTKNOWNID"
。如何使用XPATH进行合规?
由于
答案 0 :(得分:3)
使用preceding-sibling
和following-sibling
:
//p[preceding-sibling::h2/span[@id="KNOWNID"] and following-sibling::h2/span[@id="NEXTKNOWNID"]]