Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select text node by value

Tags:

xml

xpath

Given the desire to use XPath to select an XML Text Node based on its value, is there a better way than:

//*[text()="foo"]/text()

I'm assuming that there's something like:

//text()[self="foo"]

...but I don't know what to put for self.

like image 623
Phrogz Avatar asked Mar 27 '26 08:03

Phrogz


1 Answers

In XPath the period or dot character . is the self, also known as the "context node".

This query…

//text()[.="foo"]

…will select all text nodes with the value of "foo".

like image 77
Phrogz Avatar answered Mar 29 '26 01:03

Phrogz