How can I parse xml nodes returned from rest service. I programmed already on xamarin pcl cross-platform, I used many strategies but not one availed here is my working method. I want the string returned to be parsed and bind the node's value to the listview control of xamarin.forms.
ps: xdocument is not working for my case,xmldocument tooenter code also ,sorry for over-verbose.
public async Task<string> httpRequest(string url)
{
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
string received;
using (var response = (HttpWebResponse)(await
Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse,request.EndGetResponse, null)))
{
using (var responseStream = response.GetResponseStream())
{
using (var sr = new StreamReader(responseStream))
{
received = await sr.ReadToEndAsync();
}
}
}
}
async Task<your_type> DeserialseXMLStringFromURL(string url)
{
var xmlstring = await httpRequest(url);
XmlSerializer serializer = new XmlSerializer(typeof(List<your_type>));//initialises the serialiser
List<your_type> deserializedList;
deserializedList = (List<your_type>)serializer.Deserialize (xmlstring);
return deserializedList;
}
// Create a class for your type with properties.
public class your_type
{
[XmlElement("property_name_in_xml")]
public string Property_One{ get; set;}
....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.