In the InnerHTML, HTMLAgilityPack parses

c# html-agility-pack

Question

<div>
<b>Token1</b>
Token2
<b>Token3</b>
</div>

I endeavor to remove Token2 from the div.

I am able to get Tokens 1 and 3 using:

HtmlNodeCollection headerFooter = doc.DocumentNode.SelectNodes("//div//b");

How can I directly extract Token2 using HTMLAgilityPack?

Token1 and Token2 may be replaced in the doc with string.empty as a quick fix. DocumentNode. SelectNodes("/div"). InnerText, although I suppose HTMLAgilityPack could have done it more aesthetically pleasingly.

1
2
8/28/2009 10:22:49 AM

Expert Answer

You should be able to look at "/div/text()" and concatenate since the text is in the text nodes:

StringBuilder sb = new StringBuilder();
foreach (HtmlAgilityPack.HtmlTextNode node in
      doc.DocumentNode.SelectNodes("//div/text()"))
{
    sb.Append(node.Text.Trim());
}
string s = sb.ToString();
6
8/28/2009 10:35:25 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow