title: XmlReader and MemoryStream, the returned xml misses tags
body: <p>Could someone explain this behaviour to me?</p>
  
  <p>If you execute the snippet at the bottom of the post with the first string, it returns the exact same string as the one used for the input; that's what I expected.</p>
  
  <p>input 1: </p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Company&gt;
    &lt;Creator&gt;Me&lt;/Creator&gt;
    &lt;CreationDateTime&gt;2010-01-25T21:58:32.493&lt;/CreationDateTime&gt;
    &lt;Contacts&gt;
      &lt;Contact&gt;
        &lt;ContactID&gt;365&lt;/ContactID&gt;
      &lt;/Contact&gt;
    &lt;/Contacts&gt;
  &lt;/Company&gt;
  </code></pre>
  
  <p>output 1:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Company&gt;
    &lt;Creator&gt;Me&lt;/Creator&gt;
    &lt;CreationDateTime&gt;2010-01-25T21:58:32.493&lt;/CreationDateTime&gt;
    &lt;Contacts&gt;
      &lt;Contact&gt;
        &lt;ContactID&gt;365&lt;/ContactID&gt;
      &lt;/Contact&gt;
    &lt;/Contacts&gt;
  &lt;/Company&gt;
  </code></pre>
  
  <p>Now if you use the second line (<code>const string xml</code>), which is exaclty the same string but on one line instead of two it returns the following</p>
  
  <p>intput 2</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Company&gt;
    &lt;Creator&gt;Me&lt;/Creator&gt;
    &lt;CreationDateTime&gt;2010-01-25T21:58:32.493&lt;/CreationDateTime&gt;
    &lt;Contacts&gt;
      &lt;Contact&gt;
        &lt;ContactID&gt;365&lt;/ContactID&gt;
      &lt;/Contact&gt;
    &lt;/Contacts&gt;
  &lt;/Company&gt;
  </code></pre>
  
  <p>output 2 </p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Creator&gt;Me&lt;/Creator&gt;2010-01-25T21:58:32.493 
  &lt;Contacts&gt;
    &lt;Contact&gt;
      &lt;ContactID&gt;365&lt;/ContactID&gt;
    &lt;/Contact&gt;
  &lt;/Contacts&gt;
  </code></pre>
  
  <p>The only difference between the 2 is that the first one has a line break right after the xml declaration but as you can see the second output misses the Parent tag and the third tag. Any thought?</p>
  
  <p>Here is the code I used:</p>
  
  <pre><code>public void XmlReader_Eats_Tags_IsTrue()
      {
          //this first xml declaration is on two lines - line break is right after the xml declaration (I am not sure how to add the line break using the markdown, so if you execute the code on your machine, please add it)
          const string xml = @"&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;Company&gt;&lt;Creator&gt;Me&lt;/Creator&gt;&lt;CreationDateTime&gt;2010-01-25T21:58:32.493&lt;/CreationDateTime&gt;&lt;Contacts&gt;&lt;Contact&gt;&lt;ContactID&gt;365&lt;/ContactID&gt;&lt;/Contact&gt;&lt;/Contacts&gt;&lt;/Company&gt;";
  
          //The seconde xml declaration is on one line
          //const string xml = @"&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;Company&gt;&lt;Creator&gt;Me&lt;/Creator&gt;&lt;CreationDateTime&gt;2010-01-25T21:58:32.493&lt;/CreationDateTime&gt;&lt;Contacts&gt;&lt;Contact&gt;&lt;ContactID&gt;365&lt;/ContactID&gt;&lt;/Contact&gt;&lt;/Contacts&gt;&lt;/Company&gt;";
  
          BufferedStream stream = new BufferedStream(new MemoryStream());
          stream.Write(Encoding.ASCII.GetBytes(xml), 0, xml.Length);
          stream.Seek(0, SeekOrigin.Begin);
          StreamReader streamReaderXml = new StreamReader(stream);
  
          XmlReader xmlR = XmlReader.Create(streamReaderXml);
  
          XmlReaderSettings xmlReaderset = 
                           new XmlReaderSettings{ValidationType = ValidationType.Schema};
          xmlReaderset.Schemas.ValidationEventHandler += ValidationCallBack;
  
          MemoryStream ms = new MemoryStream();
          XmlWriterSettings xmlWriterSettings = 
                            new XmlWriterSettings{
                                    Encoding = new UTF8Encoding(false),
                                    ConformanceLevel = ConformanceLevel.Fragment
                            };
  
          using (XmlWriter xmlTw = XmlWriter.Create(ms, xmlWriterSettings))
          {
              using (XmlReader xmlRead = XmlReader.Create(xmlR, xmlReaderset))
              {
                  int i = 0;
                  while (xmlRead.Read())
                  {
                      Console.WriteLine("{0}:{1}; node type: {2}", i, xmlRead.Name, xmlRead.NodeType);
                      // Reads the whole file and will call the validation handler subroutine if an error is detected.
                      xmlTw.WriteNode(xmlRead, true);
                      i++;
                  }
  
                  xmlTw.Flush();
                  xmlRead.Close();
              }
              string xmlString = Encoding.UTF8.GetString(ms.ToArray());
              Console.WriteLine(xmlString);
          }
      }
  </code></pre>