I have a HTML table (well I didn't make it but I am using it, just to clear that up) with many rows and a few columns.
I want to get some of the data into a string to use as a tooltip. The way I am doing it now is reading the contents of the HTML file as a string and using string manipulation to get the data I want.
This is probably a very bad idea, so I was wondering if there is any API I could use to read text from a specific row and column in a HTML file (like row 2 column 2). I would prefer not using an external .dll library file but I'll have to use it if there is no other way.
Any ideas?
HTML Agility Pack
There are some good examples of how to use the HTML Agility Pack.
Refer links posted by rtpHarry
in this answer
An example from the codeplex site as to how you would fix all hrefs in an HTML file using the HTML agility pack:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{
HtmlAttribute att = link["href"];
att.Value = FixLink(att);
}
doc.Save("file.htm");
One of the way could be to use library such as Html Agility Pack to load the html document and then use DOM api or xpath to navigate to required node and get the content. This may get started you on agility pack: How to use HTML Agility pack
Lastly, if your html is xhtml (or in valid xml form) then you may use xml libraries available in .NET itself to do the manipulation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With