title: Root element is missing error for .net XmlDocument.load()
body: <p>Greetings all.</p>
  
  <p>I'm getting an asp.net error "Root element is missing" when I load the results of a REST request into an XmlDocument.  The same REST request looks fine and returns valid results when I execute it using the Firefox addon "RESTTEST".  But the error shows up in the C#.net code-behind.  Does anyone know what might cause this?  Here is the relevant code:</p>
  
  <pre><code>HttpWebResponse response = null;
  response = (HttpWebResponse)request.GetResponse();
  HttpStatusCode statusCode = response.StatusCode;
  Stream responseData = response.GetResponseStream();
  StreamReader sr = new StreamReader(responseData);
  XmlTextReader reader = new XmlTextReader(sr);
  XmlDocument doc = new XmlDocument();
  doc.Load(sr); // here is where the error occurs.
  </code></pre>
  
  <p>My goal is to load the results of the REST request into a traverse-able XML data model which I can then grab elements and their values from.</p>
  
  <p>When I use this code, I get the expected results.  What is the difference?</p>
  
  <pre><code>while (reader.Read())
  {
    switch (reader.NodeType)
    {
      case XmlNodeType.Element: // The node is an Element.
        Response.Write("Element Name: " + reader.Name);
        while (reader.MoveToNextAttribute()) // Read attributes.
        Response.Write(" " + reader.Name + "='" + reader.Value + "'");
        Response.Write("&lt;br /&gt;");
        break;
      case XmlNodeType.Text: //Display the text in each element.
        Response.Write("Element value: " + reader.Value);
        Response.Write("Read key=" + reader.Name + ", value=" + reader.Value + "&lt;br/&gt;");
        break;
      case XmlNodeType.EndElement: //Display end of element.
        Response.Write("&lt;br /&gt;");
        break;
      }
    }
  </code></pre>