地理编码时找不到文件:xml版本=1.0编码=UTF-8



我收到这个错误消息

找不到文件<?xml版本="1.0"编码="UTF-8">

下面是代码。如何解决这个问题?感谢你的帮助。

rivate void button1_Click(对象发件人,RoutedEventArgs e){string sPath="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+露天剧场+公园大道,+山地+景观,+CA&sensor=false";WebClient wc=新WebClient();wc。DownloadStringAsync(新Uri(sPath));wc。DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);}void wc_DownloadStringCompleted(对象发送方,DownloadStringCompletedEventArgs e){XDocument-xdoc=XDocument.Load(e.Result);XElement locationElement=xdoc。元素("GeocodeResponse")。元素("result")、元素("geometry")和元素("location");double latitude=(double)locationElement.Element("lat");double经度=(double)locationElement.Element("lng");txtBlkLatLon.Text=纬度。ToString()+","+经度。ToString();}

更换

XDocument xdoc = XDocument.Load(e.Result);

通过

XDocument xdoc = XDocument.Parse(e.Result);

前者试图在字符串指定的位置加载数据(该字符串包含数据,而不是位置)。

后者,是尝试直接读取数据。

异常究竟发生在哪里?

您是否尝试过使用XDocument.Passe从字符串创建XDocument?http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.parse.aspx

您还应该在调用DownloadStringAsync之前附加DownloadStringCompleted事件处理程序

相关内容

最新更新