0

我正在制作网络应用程序。我将 httpresponse 放入 xml 文件中,所以我希望首先将这个 xml 文件排列在数据表中,然后绑定到网格视图中。

这是我的代码:-

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{

     StreamReader responsereader = new StreamReader(response.GetResponseStream());

     var responsedata = responsereader.ReadToEnd();
     xmldoc = (XmlDocument)JsonConvert.DeserializeXmlNode(responsedata);
     xmldoc.Save(@"C:\New folder\myfile.xml");

         DataTable dt = new DataTable();
         DataRow dr;
         dt.Columns.Add("hotelId");
         dt.Columns.Add("name");
         dt.Columns.Add("address1");
         dt.Columns.Add("address2");
         dt.Columns.Add("city");
         dt.Columns.Add("postalCode");
         dt.Columns.Add("countryCode");
         dr = dt.NewRow();

         XmlSerializer serializer = new XmlSerializer(typeof(HotelListResponse));
         HotelListResponse hx = new HotelListResponse();
         hx.Items = new hoteltype[7];

       Stream reader = new FileStream(@"C:\New folder\myfile.xml", FileMode.Open);

       HotelListResponse hlist = (HotelListResponse)serializer.Deserialize(reader);

           dt.ReadXml(@"C:\New folder\myfile.xml");
           //foreach(hoteltype ht in hlist.htype){
           this.GridView1.Visible = true;
           GridView1.DataSource = dt;
           GridView1.DataBind();
           //} 

          //responsereader.Close();
           //request.GetResponse().Close();

       }
   }
     catch (WebException ex)
     {
         if (ex.Response == null)
             throw new NullReferenceException("WebException response");
         throw ex;
     }

}

这里 HotelListResponse 我的类文件。实际上在程序中我正在使用自定义属性。我正在发布 Pastbin 链接,它也包含我的整个代码。

http://pastebin.com/C2q4JYYt

4

0 回答 0