Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi

From morning I tried to convert the xml.gz to dataset, I am getting error. can any one help me.

C#
public void FnSearchTorix()
       {
       string AuthResponse = new WebClient().DownloadString("http://www.hotelspro.com/xf_3.0/downloads/KT6193hotellist.xml.gz");
        DataSet DSAuth = new DataSet();
       DSAuth = ConvertXMLToDataSet(AuthResponse);
       DataTable dt = new DataTable();
       dt = DSAuth.Tables[0];
       }


       private DataSet ConvertXMLToDataSet(string xmlData)
       {
           String xmlRes = String.Empty;
           FileStream stream = new FileStream(xmlData, FileMode.Create);

           GZipStream responseStream = new GZipStream(stream, CompressionMode.Decompress);
           responseStream.Flush();
           StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.Default);
           System.Text.StringBuilder sbOutput = new System.Text.StringBuilder();
           char[] buffer = new char[4096];
           int r;
           while ((r = sr.Read(buffer, 0, buffer.Length)) > 0)
               sbOutput.Append(buffer, 0, r);
           xmlRes = sbOutput.ToString();
           DataSet xmlDS = new DataSet();
           StringReader stream1 = null;
           XmlTextReader reader1 = null;
           try
           {
               stream1 = new StringReader(xmlRes);
               // Load the XmlTextReader from the stream
               reader1 = new XmlTextReader(stream);
               xmlDS.ReadXml(reader1);
               return xmlDS;
           }
           catch
           {
               return null;
           }
           finally
           {
               if (reader1 != null) reader1.Close();
           }
       }
Posted
Updated 7-Apr-15 21:07pm
v2
Comments
Maciej Los 8-Apr-15 3:08am    
What kind of issue do you have? What kind of error? Which line?
Please, be more specific and provide more details. Use "Improve question" widget to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900