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


Parsing problem


Hi, found parsing problem with following html code:
<html id="thisisTest">
<body id="test">
    <br />
    This is plain text
All going well for HTML, HEAD, TITLE, BODY tag, they all appear as proper child tree (e.g. HEAD is child of HTML, TITLE is child of HEAD etc.) but then you get to BODY tag, all elements in the BODY tag pear as it children no matter in what tag they are located in. Good example is FORM tag.
Closed Aug 23, 2012 at 2:57 PM by DarthObiwan
This bug has been fixed as of 1.4.5. It is available in nuget, here on codeplex and via the source code


DarthObiwan wrote Oct 3, 2009 at 6:02 AM

In the HtmlNode class there is a list of elements and what the parser should do with those elements.
Comment out Following line and you will get the behavior your are expecting.
ElementsFlags.Add("form", HtmlElementFlag.CanOverlap | HtmlElementFlag.Empty);

This is where the power and the drawbacks HAP has when parsing Html. This line helps it deal with malformed code but unfortunately also ends up parsing it wrong when the code is correct. I'm thinking of making an xml format to define these better to make it easier to tweak. Also the list shouldn't be in html node, it should be it's own separate strongly typed collection.

wrote Apr 21, 2010 at 7:08 PM

Sarabe wrote Apr 21, 2010 at 7:16 PM

This seems to be a recurring issue for a lot of people. At least 6 have voted to fix it in various tracked issues. My team is currently just using the dlls. We could get the source but it seems like overkill to fix such an easy thing... We have been using the pack for about a year now and so far this is the only issue that would inspire us to have the source. Is it possible to fix it for all?

DarthObiwan wrote Apr 22, 2010 at 3:13 AM

You can change this without recompiling. The ElementFlags list is a static property on the HtmlNode class.
It can be removed with
before doing the document load

wrote Nov 18, 2010 at 8:23 PM

wrote Mar 10, 2011 at 10:21 AM

wrote Apr 3, 2011 at 11:30 PM

wrote May 27, 2011 at 10:21 AM

wrote May 24, 2012 at 2:34 PM

emn13 wrote Aug 23, 2012 at 2:11 PM

This bug is also fixed by the patch to

wrote Aug 23, 2012 at 2:57 PM

wrote Feb 22, 2013 at 2:47 AM

wrote May 16, 2013 at 1:32 PM