title: Invalid XML document, The document does not have a root element
body: <pre><code> private void btnmap_Click(object sender, EventArgs e)
   { 
   XmlDocument xmldoc = new XmlDocument();
                   XmlNode xmlnode, xmlroot, docNode, Doc;
                   XmlAttribute xmlatt;
                   docNode = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                   xmldoc.AppendChild(docNode);                
                   if (rchtextfile.Text == "")
                   {
                       MessageBox.Show("Please Select a Text file", "File Name Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                   }
                   else
                   {
                       con = new System.Data.SqlClient.SqlConnection();
                       DataSet ds = new DataSet();
                       con.ConnectionString = @"Server=MDS-SW02; User ID=sa; Pwd=Admin2011; Initial Catalog=xml;";
                       con.Open();
                       MessageBox.Show("Database Connected");                    
                       String sql = "select Styles from Xml_Tags,pdfelement where Xml_Tags.Mapping_Id=pdfelement.Mapping_Id AND Xml_Tags.Pdf_Tag=pdfelement.Element_Name AND pdfelement.Style=Xml_Tags.Styles";
                       com = new SqlCommand(sql);
                       da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
                       da.Fill(ds, "xml");
                       maxrows = ds.Tables["xml"].Rows.Count;
                       StreamReader objReader = new StreamReader(file, Encoding.Default, true);
                       do
                       {                       
                           for (int i = 0; i &lt; maxrows; i++)
                           {                           
                               dRow = ds.Tables["xml"].Rows[i];                             
                               line = objReader.ReadLine();
                               if (line == null)
                               {
                                   //xmldoc.Save(ya);
                               }
                               else
                               {
                                   string st1 = "&gt;";
                                   string st2 = "&lt;/";
                                   int end = line.IndexOf(st2);
                                   if (end != -1 &amp;&amp; end &gt; 1)
                                   {
                                       st = line.IndexOf(st1);
                                       en = line.IndexOf(st2);
                                       int v = en - st;
                                       sub = line.Substring(st + 1, v - 1);
                                       rchtext.Text = rchtext.Text + sub + "\r\n";
                                   }                                                                  
                                   String sqll = "select Dtd_Tag from Xml_Tags,pdfelement where Xml_Tags.Mapping_Id=pdfelement.Mapping_Id AND Xml_Tags.Pdf_Tag=pdfelement.Element_Name AND pdfelement.Style=Xml_Tags.Styles";
                                   SqlCommand comm = new SqlCommand(sqll);
                                   SqlDataAdapter daa = new System.Data.SqlClient.SqlDataAdapter(sqll, con);
                                   DataSet ds1 = new DataSet();
                                   daa.Fill(ds1, "xml");
                                   dRow1=ds1.Tables["xml"].Rows[i];                                
                                   String sqlll = "select Dtd_Attribute_Name from Mapped_Tags_Attributes,Xml_Tags where Mapped_Tags_Attributes.Pdf_Tag=Xml_Tags.Pdf_Tag AND Mapped_Tags_Attributes.Mapping_Id=Xml_Tags.Mapping_Id";
                                   SqlCommand cmd = new SqlCommand(sqlll);
                                   SqlDataAdapter dt = new System.Data.SqlClient.SqlDataAdapter(sqlll, con);
                                   DataSet ds2 = new DataSet();
                                   dt.Fill(ds2, "xml");
                                   dRow2 = ds2.Tables["xml"].Rows[i];
                                   name = XmlConvert.EncodeName(dRow1.ItemArray.GetValue(0).ToString());
                                   xmlnode = xmldoc.CreateElement(name);
                                   Doc = xmldoc.CreateDocumentType(name, null, "E:\\Rachana_mds\\proj\\pdfextraction\\docbook.dtd", null);                                
                                   xmlroot = xmldoc.CreateElement(name);                                 
                                   xmlatt = xmldoc.CreateAttribute(dRow2.ItemArray.GetValue(0).ToString());
                                   xmlroot.AppendChild(xmlnode);
                                   xmlnode.InnerText = sub;                                                                
                               }
                           }
                       }                    
                       while (dRow[0].ToString()!=line &amp;&amp; !objReader.EndOfStream);
                           MessageBox.Show("Done");
                           string filename = @"E:" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Minute + ".xml";                         
                           xmldoc.Save(filename);                                                  
                           MessageBox.Show("Successfully saved");                                              
                   }                
                   con.Close();              
  }
  </code></pre>
  
  <p>I am getting error for this line. <code>...xmldoc.Save(filename);</code></p>