title: This operation would create an incorrectly structured document
body: <p>I am new to <code>XML</code> and tried the following but I'm getting an exception.  Can someone help me?  </p>
  
  <p>The exception is <code>This operation would create an incorrectly structured document</code></p>
  
  <p>My code:</p>
  
  <pre><code>string strPath = Server.MapPath("sample.xml");
  XDocument doc;
  if (!System.IO.File.Exists(strPath))
  {
      doc = new XDocument(
          new XElement("Employees",
              new XElement("Employee",
                  new XAttribute("id", 1),
                      new XElement("EmpName", "XYZ"))),
          new XElement("Departments",
              new XElement("Department",
                  new XAttribute("id", 1),
                      new XElement("DeptName", "CS"))));
  
      doc.Save(strPath);
  }
  </code></pre>