Xpath: how can you select specific node text before and after the tag?

consider this

 Alcohol list
Beer
<br>
Vodka
<br>
rum
<br>
whiskey

how would you express beer in xpath?

/br/preceding-sibling::text() ?

how about vodka? rum?

+3
source share
1 answer

It depends on the context. Ideally, in order to be well-formed XML, your sequence needs a root element. Let's say <bar/>.

Beer: /bar/br[1]/preceding-sibling::text()[1]

Vodka: /bar/br[1]/following-sibling::text()[1]

Rum: /bar/br[2]/following-sibling::text()[1]

+4
source

Source: https://habr.com/ru/post/1720374/


All Articles