title: HTMl agility pack error parsing and returning XElement
body: <p>I can parse the document and generate an output however the output cannot be parsed into an XElement because of a p tag, everything else within the string is parsed correctly.</p>
  
  <p>My input:</p>
  
  <pre><code>var input = "&lt;p&gt; Not sure why is is null for some wierd reason!&lt;br&gt;&lt;br&gt;I have implemented the auto save feature, but does it really work after 100s?&lt;br&gt;&lt;/p&gt; &lt;p&gt; &lt;i&gt;Autosave?? &lt;/i&gt; &lt;/p&gt; &lt;p&gt;we are talking...&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;hr&gt;&lt;p&gt;&lt;br class=\"GENTICS_ephemera\"&gt;&lt;/p&gt;";
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>public static XElement CleanupHtml(string input)
      {  
  
  
      HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
  
      htmlDoc.OptionOutputAsXml = true;
      //htmlDoc.OptionWriteEmptyNodes = true;             
      //htmlDoc.OptionAutoCloseOnEnd = true;
      htmlDoc.OptionFixNestedTags = true;
  
      htmlDoc.LoadHtml(input);
  
      // ParseErrors is an ArrayList containing any errors from the Load statement
      if (htmlDoc.ParseErrors != null &amp;&amp; htmlDoc.ParseErrors.Count() &gt; 0)
      {
  
      }
      else
      {
  
          if (htmlDoc.DocumentNode != null)
          {
              var ndoc = new HtmlDocument(); // HTML doc instance
              HtmlNode p = ndoc.CreateElement("body");  
  
              p.InnerHtml = htmlDoc.DocumentNode.InnerHtml;
              var result = p.OuterHtml.Replace("&lt;br&gt;", "&lt;br/&gt;");
              result = result.Replace("&lt;br class=\"special_class\"&gt;", "&lt;br/&gt;");
              result = result.Replace("&lt;hr&gt;", "&lt;hr/&gt;");
              return XElement.Parse(result, LoadOptions.PreserveWhitespace);
          }
      }
      return new XElement("body");
  
  }
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>&lt;body&gt;
     &lt;p&gt; Not sure why is is null for some wierd reason chappy!
     &lt;br/&gt;
     &lt;br/&gt;I have implemented the auto save feature, but does it really work after 100s?
     &lt;br/&gt;
     &lt;/p&gt; 
     &lt;p&gt; 
     &lt;i&gt;Autosave?? &lt;/i&gt; 
     &lt;/p&gt; 
     &lt;p&gt;we are talking...&lt;/p&gt;
     **&lt;p&gt;**
     &lt;hr/&gt;
     &lt;p&gt;
     &lt;br/&gt;
     &lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The bold p tag is the one that did not output correctly... Is there a way around this? Am I doing something wrong with the code?</p>