HtmlAgilityPack: Could someone please explain exactly what is the effect of setting the HtmlDocument OptionAutoCloseOnEnd to true?
<p>The current documentation says:</p>

<blockquote>
  <p>Defines if closing for non closed nodes must be done at the end or directly in the document.
      Setting this to true can actually change how browsers render the page. Default is false.</p>
</blockquote>

<p>Sorry, I have to admit I do not understand this paragraph. Specifically "at the end" of what? And what does "in the document" mean exactly? The phrase before the last one sounds ominous. If the option is set to true and if the html is formatted properly is this still going to affect the document? </p>

<p>I looked in the source code but I did not understand what's happening - the code reacts to the property not being set to true. See <a href="http://htmlagilitypack.codeplex.com/SourceControl/latest#Trunk/HtmlAgilityPack/HtmlNode.cs" rel="nofollow noreferrer">HtmlNode.cs</a>, and search for OptionAutoCloseOnEnd - line 1707. I also found some funky code in <a href="http://htmlagilitypack.codeplex.com/SourceControl/latest#Trunk/HtmlAgilityPack/HtmlWeb.cs" rel="nofollow noreferrer">HtmlWeb.cs</a> at lines 1113 and 1154. Too bad the source code browser doesn't show line numbers but search for OptionAutoCloseOnEnd in the page. </p>

<p>Could you please illustrate with an example what this option does? </p>

<p>I am using the HtmlAgilityPack to fix some bad html and to export the page content to xml.</p>

<p>I came across some badly formatted html - overlapping tags. Here is the snippet:</p>

<pre><code>&lt;p&gt;Blah bah
&lt;P&gt;&lt;STRONG&gt;Some Text&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/p&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;/STRONG&gt;Item 1.&lt;/LI&gt;
&lt;LI&gt;Item 2&lt;/LI&gt;
&lt;LI&gt;Item 3&lt;/LI&gt;&lt;/UL&gt;
</code></pre>

<p>Note that the first p tag is not closed and note the overlapping STRONG tag.</p>

<p>If I set OptionAutoCloseOnEnd this gets somehow fixed. I am trying to understand what exactly is the effect of setting this property to true in general in the structure of the document.</p>

<p>Here is the C# code that I am using:</p>

<pre><code>HtmlDocument doc = new HtmlDocument();
doc.OptionOutputAsXml = true;
doc.OptionFixNestedTags = true;      
//  doc.OptionAutoCloseOnEnd = true;    
doc.LoadHtml(htmlText);
</code></pre>

<p>Thank you!</p>