2
Reply

Exception at the time of Writing xml File

Smart    Lucky

Smart Lucky

Apr 15 2011 4:04 AM
2k
hi

I am writing following program means i want to write an xml file but value com from database but it is giving me an exception can any one help me.....?


Token StartAttribute in state Element Content would result in an invalid XML document. /// This is Exception which is thrown




        XmlWriter DocWrite = XmlWriter.Create(Server.MapPath("~/MyProfile.xml"));
        string source = @"server=KBBALOCH-PC\SQLEXPRESS; integrated security=true; database=test";
        con = new SqlConnection(source);
        con.Open();
        string query = "select * from Table_1";
        cmd = new SqlCommand(query, con);
        reader = cmd.ExecuteReader();
        DocWrite.WriteStartDocument();
        DocWrite.WriteStartElement("BioDATA");
        while (reader.Read()) 
        {
            DocWrite.WriteStartElement("Name");
           DocWrite.WriteElementString("FName", reader["name"].ToString());
           DocWrite .WriteAttributeString("Gender",reader["gender"].ToString());
           DocWrite.WriteEndElement();
        }
        DocWrite.WriteEndElement();
        DocWrite.WriteEndDocument();
        DocWrite.Close();
        con.Close();




























Answers (2)