Reputation: 367
How do I select "SomeText2" using HtmlAgilityPack for C#? I've tried var nodes = doc.DocumentNode.SelectNodes("/div[@class='hello']/br")
but that doesn't seem to do it right.
<div class="hello">SomeText1<br />
SomeText2</div>
Upvotes: 0
Views: 428
Reputation: 128
or this one selecting last text node inside a div
/div[@class='hello']/child::text()[last()]
Upvotes: 1
Reputation: 27996
I would change your XPath expression from
"/div[@class='hello']/br"
to
"/div[@class='hello']/br[last()]/following-sibling::text()[1]"
That would be the first text node after the last <br/>
element child of the <div>
that has class='hello'
.
Upvotes: 3