public static Collection <WeatherLocation> SearchCity(string city) { var result = new Collection <WeatherLocation>(); string str; using (var client = new WebClient()) { try { str = client.DownloadString(SearchUrl + city); } catch (WebException) { return(result); } } try { var data = new XmlDocument(); data.LoadXml(str); var elements = data.SelectNodes("//search/loc"); if (elements != null) { foreach (XmlElement element in elements) { var temp = new WeatherLocation { LocId = element.GetAttribute("id"), LocType = element.GetAttribute("type"), Name = element.InnerText }; result.Add(temp); } } } catch (XmlException) { } catch (XPathException) { } return(result); }
public static Collection<WeatherLocation> SearchCity(string city) { var result = new Collection<WeatherLocation>(); string str; using (var client = new WebClient()) { try { str = client.DownloadString(SearchUrl + city); } catch (WebException) { return result; } } try { var data = new XmlDocument(); data.LoadXml(str); var elements = data.SelectNodes("//search/loc"); if (elements != null) foreach (XmlElement element in elements) { var temp = new WeatherLocation { LocId = element.GetAttribute("id"), LocType = element.GetAttribute("type"), Name = element.InnerText }; result.Add(temp); } } catch (XmlException) { } catch (XPathException ) { } return result; }