This project has moved and is read-only. For the latest updates, please go here.

How to access <SELECT><OPTION>.InnerText

Sep 11, 2007 at 1:26 PM
(replying to entries in this forum is broken at the moment so I've created a new discussion instead...)

Html Agility Pack is HTML only as has been documented by Simon previously. One side effect of this is that the OPTION node in
<select><option>Option text</option>

has no innerText or innerHtml, because strictly, the above is not HTML (it's XHTML), and so you cannot get the text value above. ASP.NET SELECT controls generate XHTML-style OPTIONs, and so you expect to be able to get the text as well.

Great news is that it's easy to change. To change this, simply comment out the exception in HtmlNode.cs, line 91:

// JRH 070910 REMOVED to become XHTML compliant
// ElementsFlags.Add("option", HtmlElementFlag.Empty);


You will then get InnerHtml and InnerText being set for your OPTION tags.

Sep 21, 2009 at 8:42 PM

So, will removing this break the cases where the <option> tag isn't closed?


Jul 5, 2013 at 12:27 PM
You're forced to modify the source ?