WPF bind datagrid with xml returned in web response -


i getting xml of format in response web request, unable bind whit data drid in wpf.

here xml :

<population> <name>tram, joshua </name>   <id>83804</id>   <hcp>dr. krueger</hcp>   <symptoms>4</symptoms>   <range>1/17/13 - 4/13/13</range>   <last7>5</last7>   <connect>41380</connect>   <engage>5</engage>   <daysin>160</daysin>   <education>0.67</education>   <recco>encourage education</recco>   <name>riess, chuck </name>   <id>73403</id>   <hcp>dr. vockell</hcp>   <symptoms>4</symptoms>   <range>2/1/13 - 2/14/13</range>   <last7>5</last7>   <connect>41332</connect>   <engage>5</engage>   <daysin>179</daysin>   <education>0.74</education>   <recco>encourage tracking</recco>   <name>park, teruyuki </name>   <id>69235</id>   <hcp>dr. smithen</hcp>   <symptoms>3</symptoms>   <range>4/3/13 - 4/13/13</range>   <last7>5</last7>   <connect>41384</connect>   <engage>5</engage>   <daysin>35</daysin>   <education>0.15</education>   <recco> </recco>   </population> 

and here code, storing in dataset , binding datagrid shows on column not all.

webrequest request = httpwebrequest.create(url); webresponse response = request.getresponse();          dataset set = new dataset();              set.readxml(response.getresponsestream());              return set; 

i solved problem iterating on elements in xml , creating list of class objects way :

public list<population> getdata()     {         dataset ds =null;          list<population> populationlist = new list<population>();          string url = "http://www.lyfechannel.com/channels/win946/get_population.php";          webrequest request = httpwebrequest.create(url);          webresponse response = request.getresponse();          streamreader reader = new streamreader(response.getresponsestream());          xmldocument doc = new xmldocument();          doc.loadxml(reader.readtoend());           xmlnode rootnode = doc.selectsinglenode("//population");          xmlnodelist currentnodes = doc.selectnodes("//name");          var objpopulation = new population[currentnodes.count];          if (currentnodes.count != 0)         {              (int = 0; < currentnodes.count; i++)             {                 objpopulation[i] = new population();                 //objpopulation[i].name = currentnodes[i].innertext;              }          }           xmlnodelist idnodelist = doc.selectnodes("//id");          if (idnodelist.count != 0)         {              (int = 0; < idnodelist.count; i++)             {                 objpopulation[i] = new population();                 objpopulation[i].id = idnodelist[i].innertext;                   currentnodes = doc.selectnodes("//name");                   if (currentnodes.count != 0)                 {                      (int ij = 0; ij < currentnodes.count; ij++)                     {                          objpopulation[ij].name = currentnodes[ij].innertext;                      }                  }                   currentnodes = doc.selectnodes("//hcp");                   if (currentnodes.count != 0)                 {                      (int j = 0; j < currentnodes.count; j++)                     {                          objpopulation[j].hcp = currentnodes[j].innertext;                      }                  }                   currentnodes = doc.selectnodes("//symptoms");                   if (currentnodes.count != 0)                 {                      (int k = 0; k < currentnodes.count; k++)                     {                          objpopulation[k].symptoms = currentnodes[k].innertext;                      }                  }                   currentnodes = doc.selectnodes("//range");                   if (currentnodes.count != 0)                 {                      (int l = 0; l < currentnodes.count; l++)                     {                          objpopulation[l].range = currentnodes[l].innertext;                      }                  }                   currentnodes = doc.selectnodes("//last7");                   if (currentnodes.count != 0)                 {                      (int m = 0; m < currentnodes.count; m++)                     {                          objpopulation[m].last7 = currentnodes[m].innertext;                      }                  }                   currentnodes = doc.selectnodes("//connect");                   if (currentnodes.count != 0)                 {                      (int n = 0; n < currentnodes.count; n++)                     {                          objpopulation[n].connect = currentnodes[n].innertext;                      }                  }                   currentnodes = doc.selectnodes("//engage");                   if (currentnodes.count != 0)                 {                      (int o = 0; o < currentnodes.count; o++)                     {                          objpopulation[o].engage = currentnodes[o].innertext;                      }                  }                   currentnodes = doc.selectnodes("//daysin");                   if (currentnodes.count != 0)                 {                      (int p = 0; p < currentnodes.count; p++)                     {                          objpopulation[p].daysin = currentnodes[p].innertext;                      }                  }                   currentnodes = doc.selectnodes("//education");                   if (currentnodes.count != 0)                 {                      (int q = 0; q < currentnodes.count; q++)                     {                          objpopulation[q].education = currentnodes[q].innertext;                      }                  }                   currentnodes = doc.selectnodes("//recco");                   if (currentnodes.count != 0)                 {                      (int r = 0; r < currentnodes.count; r++)                     {                          objpopulation[r].recco = currentnodes[r].innertext;                      }                  }                  populationlist.add(objpopulation[i]);              }          }          mygrid.itemssource = populationlist;       } 

and here class code:

class population {      public string name { get; set; }     public string id { get; set; }     public string hcp { get; set; }     public string symptoms { get; set; }     public string range { get; set; }     public string last7 { get; set; }     public string connect { get; set; }     public string engage { get; set; }     public string daysin { get; set; }     public string education { get; set; }     public string recco { get; set; }  } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -