windows phone 7 - Deserialise XML response from server -


i want deserialise object. saw following code in msdn.com:

private void deserializeobject(string filename)     {     debug.writeline("reading xmlreader");      // create instance of xmlserializer specifying type , namespace.     xmlserializer serializer = new xmlserializer(typeof(user));      // filestream needed read xml document.     filestream fs = new filestream(filename, filemode.open);     xmlreader reader = xmlreader.create(filename);      // declare object variable of type deserialized.     user i;      // use deserialize method restore object's state.     = (user)serializer.deserialize(reader);     fs.close();      // write out properties of object.     debug.writeline(     i.field1+ "\t" +     i.field2+ "\t" +     i.field3+ "\t" +     i.field4);     } 

however, don't want deserialise file, rather xml stream server response, corresponding code shown here:

httpwebrequest webrequest = (httpwebrequest)asynchronousresult.asyncstate;             httpwebresponse response;             response = (httpwebresponse)webrequest.endgetresponse(asynchronousresult);              stream streamresponse = response.getresponsestream();             streamreader streamreader = new streamreader(streamresponse);             var response = streamreader.readtoend();             streamresponse.close();             streamreader.close();             response.close();             if (response == "")             {                 //show error msg user                     }             else             {                 //your response available in "response"                  string mystring = response.tostring();                  //mytext.text = mystring;                 debug.writeline(mystring);                 deserializeobject("myxml");  <---- call deserialise  } 

how can achieve this? created class called "user" according xml using xsd.exe tool.

ok did it. how :-

private void deserializeobject(string inxml)     {         debug.writeline("reading xmlreader");         var xml = inxml;         var serializer = new xmlserializer(typeof(user));         using (var reader = new stringreader(xml))         {             var user = (user)serializer.deserialize(reader);             debug.writeline(                             user.number + "\t" +                             user.id + "\t" +                             user.textkey + "\t" +                             user.agent );         }     } 

instead of passing file url, passed complete string. , rest shown above.

hope helpful learning.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -