Shashi
Shashi

Reputation: 2898

how to get innerTextwithin the node in HTML AGILity pack..?

<a> contents <strong>strong content</strong> </a>

I want a only the "contents" i.e present between <a> and <strong>

Upvotes: 0

Views: 361

Answers (1)

Rohit Agarwal
Rohit Agarwal

Reputation: 4289

You will have to remove the string within <strong> from string within <a> -

var testString = "<a> contents <strong>strong content</strong> </a>";
var doc = new HtmlDocument();
doc.LoadHtml(testString);
var strWithinAnchor = doc.DocumentNode.SelectSingleNode("/a").InnerText;
var strWithinStrong = doc.DocumentNode.SelectSingleNode("/a/strong").InnerText;
var resultString = strWithinAnchor.Replace(strWithinStrong, string.Empty);

Upvotes: 1

Related Questions