Reputation: 11
I need to parse a string in C# to find out code for a Particular HTML element with a given ID.
For Example:
I have a string with complete source code of a URL in it. How can I parse the string to find the inner HTML of an element of a given ID say 1,2,3...
Upvotes: 0
Views: 794
Reputation: 24116
Use a third party HTML parser like HTML Agility Pack.
Don't write one yourself.
Example usage:
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");
Src: http://htmlagilitypack.codeplex.com/wikipage?title=Examples
Upvotes: 2