Reputation: 233
I am try to select the "string b" text node using XPath with the HtmlAgilliyPack.
<div>
string a<br/>
string b<br/>
string c<br/>
</div>
I am not sure how to select the text?
This won't work //div/text(1)
Anybody has some suggestions?
Upvotes: 0
Views: 178
Reputation: 9627
Try:
//div/br[1]/following-sibling::text()[1]'
The direct following text after the first br
.
Upvotes: 0
Reputation: 38732
There are two problems with your expression:
text()
is a node filter which does not accept arguments. If you want to limit to the second text node, use the predicate [position() = 2]
or the short version [2]
.Use this expression:
//div/text()[2]
Selecting text nodes can include some hassles, chopping leading and trailing whitespace and omitting whitespace-only text nodes is implementation-dependent.
Upvotes: 2