5

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!

Allen Gingrich
  • 5,608
  • 10
  • 45
  • 57

2 Answers2

5

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()
maerics
  • 151,642
  • 46
  • 269
  • 291
0

Use:

//a[@href='']/text()

This selects all text nodes that are children of any a element in the document, that has an empty href attribute.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431