title: Getting the name of an XML document's root node
body: <p>I have an XML file that I want to load. I want to put a condition in my code to check and make sure the root node is 'TimeLog'. If it isn't then tell the user that they picked the wrong XML file. </p>
  
  <p>In the code below, r.Name only returns an empty string. I'd expect it to return "TimeLog" but it does not. </p>
  
  <pre><code>    private void loadFromFile(object sender, EventArgs e)
      {
          if(File.Exists("TimeLog.xml"))
          {
              XmlReader r = XmlReader.Create("TimeLog.xml");
              r.MoveToContent();
              r.ReadStartElement();
              if (r.Name == "TimeLog") //The current value or r.name is "".
              {
                  while (r.Read())
                  {
                      if (r.NodeType == XmlNodeType.Element)
                      {
                          r.ReadToDescendant("EntryName");
                          String name = r.ReadInnerXml();
                          r.ReadToFollowing("StartDateTime");
                          String start = r.ReadInnerXml();
                          r.ReadToFollowing("EndDateTime");
                          String end = r.ReadInnerXml();
                          r.ReadToFollowing("Duration");
                          String dur = r.ReadInnerXml();
  
                          entries.Add(new Entry(name, start, end, dur));
                      }
                  }
              }
              else
              {
                  MessageBox.Show("This is not a TimeLog XML file", "This is not a TimeLog XML file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
              }
              r.Close();
          }
      }
  </code></pre>
  
  <p>The XML file is the output my saveToFile() function and looks like this</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TimeLog&gt;
      &lt;Entry&gt;
          &lt;EntryName&gt;Entry 01&lt;/EntryName&gt;
          &lt;StartDateTime&gt;8/21/2015 8:50:40 PM&lt;/StartDateTime&gt;
          &lt;EndDateTime&gt;1/1/0001 12:00:00 AM&lt;/EndDateTime&gt;
          &lt;Duration&gt;00:00:00&lt;/Duration&gt;
      &lt;/Entry&gt;
      &lt;Entry&gt;
          &lt;EntryName&gt;Entry 02&lt;/EntryName&gt;
          &lt;StartDateTime&gt;8/21/2015 8:50:40 PM&lt;/StartDateTime&gt;
          &lt;EndDateTime&gt;1/1/0001 12:00:00 AM&lt;/EndDateTime&gt;
          &lt;Duration&gt;00:00:00&lt;/Duration&gt;
      &lt;/Entry&gt;
  &lt;/TimeLog&gt;
  </code></pre>
  
  <p>How can I check to make sure the name of the Root Node is "TimeLog" without calling another .Read() function and throwing the order off for the code in the while statement?</p>