Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Atomic Value between Element Nodes using XPath

I want to select only the atomic values inside a node. For example, the "here" text in the following:

<a href="">here</a>

When I use Xpath in Java, it returns some sort of object/array, such as

[DomNode[<a href="">here</a>]]

I just want the text only.

Is this possible, and how? Thanks!

like image 712
Allen Gingrich Avatar asked Jul 22 '10 17:07

Allen Gingrich


1 Answers

You can use the text() node test. For example, if you want to select the text of all anchors with an href attribute you could do the following XPath query:

//*/a/@href/../text()
like image 56
maerics Avatar answered Oct 07 '22 19:10

maerics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!