InnerText not set?

Topics: Developer Forum
Sep 11, 2007 at 12:16 PM
Hi all, based on another post I have a baseline test which is simply not working: it appears HtmlAgilityPack is not reliably storing InnerText or InnerHtml?

NOTE this INTENTIONALLY gets all options across both SELECTs (otherwise I'd use ".//option"):

HtmlDocument doc = new HtmlDocument();
StringReader st = new StringReader("<html><select id=\"s1\"><option value=\"1\">One</option><option value=\"2\">Two</option></select><select id=\"s2\"><option value=\"3\">Three</option><option value=\"4\">Four</option></select></html>");
doc.Load(st);
HtmlNodeCollection options = doc.DocumentNode.SelectNodes("//option@value");
System.Console.WriteLine("Listing options for document");
foreach (HtmlNode option in options)
{
System.Console.WriteLine("option value '{0}', text '{1}'", option.Attributes"value".Value, option.InnerText);
}

Produces:

Listing options for document
option value '1', text ''
option value '2', text ''
option value '3', text ''
option value '4', text ''

Instead of expected:

option value '1', text 'One'
option value '2', text 'Two'
option value '3', text 'Three'
option value '4', text 'Four'

any ideas? It looks like I have to discard HtmlAgilityPack but I'm really trying to avoid it?
Dec 5, 2007 at 9:04 PM
Look at this posting ? : http://www.codeplex.com/htmlagilitypack/Thread/View.aspx?ThreadId=14982