开发者

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 so开发者_运维知识库rt of object/array, such as

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

I just want the text only.

Is this possible, and how? Thanks!


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()


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜