I am creating a windows phone 8 app. In it I am downloading a xml file from a url using WebClient. The downloaded result shows something like this:
[{"PersonNo":"1","PersonName":"Kaustav","Address":"Kolkata"},{"PersonNo":"2","PersonName":"Jay","Address":"Mumbai"}
{"PersonNo":"3","PersonName":"Rants","Address":"Chennai"}]
When I passes this to the Parse method of XDocument it generates an exception:
An exception of type 'System.Xml.XmlException' occurred in System.Xml.ni.dll but was not handled in user code. Additional information: Data at the root level is invalid. Line 1, position 1.
My code is:
private void getPersons()
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpCompleted;
wc.DownloadStringAsync(new Uri("http://ift.tt/1oUmxIn"));
}
private void HttpCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var loadedData = XDocument.Parse(e.Result); //problem in this line
//display person info
}
Here the url is changed for security reasons. So how to parse this downloaded xml file to XDocument?
No comments:
Post a Comment