Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath: how can you select a specific text node before and after a <br> tag?

Tags:

xpath

nokogiri

consider this

List of Alcohol
Beer
<br>
Vodka
<br>
rum
<br>
whiskey

how would you express Beer in xpath ?

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

what about vodka ? rum ?

like image 460
pingu Avatar asked Oct 17 '09 22:10

pingu


1 Answers

Depends on the context. Ideally, to be well-formed XML, your sequence needs a root element. Let's say it's <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]

like image 171
James Sulak Avatar answered Jan 03 '23 16:01

James Sulak