XHTML Parsing with HTMLAgilityPack
See the question and my original answer on StackOverflowBy default, the <OPTION>
tag is treated by Html Agility Pack as a "Empty", which means it does not need a closing </OPTION>
, that's why in this case, it's not easy to catch with XPATH. You can change this using the HtmlNode.ElementFlags collection.
Here is a code that should do what you want:
HtmlDocument doc = new HtmlDocument();
HtmlNode.ElementsFlags.Remove("option");
doc.LoadHtml(yourHtml);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//option"))
{
Console.WriteLine(node.InnerText);
}