title: htmlagilitypack strange behaviour when using 2 htmldocument objects
body: <p>Here is the code:</p>
  
  <pre><code>HtmlDocument htmlDoc = new HtmlDocument();
  HtmlDocument segment = new HtmlDocument();
  
  htmlDoc.OptionWriteEmptyNodes = true;
  segment.OptionWriteEmptyNodes = true;            
  
  htmlDoc.Load("sourcepath");
  segment.Load("sourcepath");
  
  //Fix HtmlAgilityPack bug with ending tag at xmldeclaration
  var newNodeStr = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;";
  var newNode = HtmlNode.CreateNode(newNodeStr);
  htmlDoc.DocumentNode.ReplaceChild(newNode, htmlDoc.DocumentNode.FirstChild);
  segment.DocumentNode.ReplaceChild(newNode, segment.DocumentNode.FirstChild);    
  
  HtmlNode sbodyNode = segment.DocumentNode.SelectSingleNode("//body");
  if (sbodyNode != null)
  sbodyNode.RemoveAllChildren();
  
  HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
  int numberOfChilds = bodyNode.ChildNodes.Count;
  MessageBox.Show(numberOfChilds.ToString());
  
  segment.Save("destpath1", Encoding.UTF8);
  htmlDoc.Save("destpath2", Encoding.UTF8);
  </code></pre>
  
  <p>Input is simple xhtml. I want to modify an xhtml file(this is represented by htmlDoc). For this i created another HtmlDocument object(segment, load the same xhtml into it). As a first step i am trying to strip all the children of the body element. Then i would add some of the elements back using htmlDoc obeject. The problem with the above is that removing these from segment affects htmlDoc(the other object) too. So the MessageBox will show 0 always. On top of this if i look at the outputs, which is produced by the Save functions, htmlDoc will have elements under the , which would mean that the MessageBox should show the number of them(as far as  i guess).(Note: If i uncomment the RemoveAllChildren() line then the MessageBox shows the correct number.)
  I think its some trivial stuff, but it's kinda strange for me. Thanks for your help.</p>
  
  <p><strong>Update:</strong> Sorry i didn't post the full code beacuse i thought some lines are irrelevant, but looks like they are not. If i comment out those 4 lines after the Loads, i get the right numbers and it works like expected. The question is why those lines do "harm". (these lines i wrote to fix the output, because agilitypack made the xml header closing tag /> instead of ?>)</p>