「このイベントについて:」というテキストを含む子<strong>要素を持つ<p>要素の後に<p>要素を取得するxpath式を作成するにはどうすればよいですか。
つまり、どのパス式で「<p>」要素が得られ、<P>の後に「Hello」テキストが続き、その下に<Strong>テキストがあります…</ p>
<p>
<strong>About this event:</strong>
…
</p>
<p>Hello</p>
?-
「このイベントについて:」というテキストを含む子<strong>要素を持つ<p>要素の後に<p>要素を取得するxpath式を作成するにはどうすればよいですか。
つまり、どのパス式で「<p>」要素が得られ、<P>の後に「Hello」テキストが続き、その下に<Strong>テキストがあります…</ p>
<p>
<strong>About this event:</strong>
…
</p>
<p>Hello</p>
?-
//p[strong[.='About this event:']]/following-sibling::p
また
//p[strong[.='About this event:']]/following-sibling::p[.='Hello']
これを試して:
//p[normalize-space(strong)='About this event:']/following-sibling::p
p
次を追加して、これを最初に絞り込むこともできます[1]
。
//p[normalize-space(strong)='About this event:']/following-sibling::p[1]
これはできるはずだと思います。Perl のxpath
ツールからの出力は次のとおりです。
so zacharyyoung$ xpath so.xml '//p[strong = "About this event:"]/following-sibling::p[1]'
Found 1 nodes:
-- NODE --
<p>Hello</p>
XPath は//p[strong = "About this event:"]/following-sibling::p[1]