windows phone 7 - parse xml return after a post method -
i use post post parameter server , result in string, how parse result , bind listbox? seems (for reason) can't output string textblock or messagebox. parse xml use xdocument (which take stream in parameter) code following:
private static void getrequeststreamcallback(iasyncresult asynchronousresult) { string post = "track=love"; // post = httputility.urlencode(post); console.writeline(post); try { httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate; // end operation stream poststream = request.endgetrequeststream(asynchronousresult); // convert string byte array. byte[] postbytes = encoding.utf8.getbytes(post); // write request stream. poststream.write(postbytes, 0, postbytes.length); poststream.close(); // start asynchronous operation response request.begingetresponse(new asynccallback(getresponsecallback), request); } catch (exception ex) { messagebox.show(ex.tostring()); } } private static void getresponsecallback(iasyncresult asynchronousresult) { httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate; // end operation httpwebresponse response = (httpwebresponse)request.endgetresponse(asynchronousresult); httpstatuscode rcode = response.statuscode; stream streamresponse = response.getresponsestream(); streamreader streamread = new streamreader(streamresponse); //this return "" value, expect return xml string string str = streamread.readtoend(); //console.writeline(responsestring); // close stream object streamresponse.close(); streamread.close(); // release httpwebresponse response.close(); }
and want use xdocument parse data this:
xdocument xdoc = xdocument.load(str); var data = query in xdoc.descendants("tracks").elements("item") select new searchresult { artist = (string)query.element("artist"), album = (string)query.element("album"), track = (string)query.element("track"), // artista = (string)query.element("artists").element("artist"), }; listbox1.itemssource = data; var data1 = query in xdoc.descendants("artists").elements("item") select new searchresult { artista = (string)query.element("artist"), }; listbox2.itemssource = data1;
Comments
Post a Comment