I have the following code where I am trying to make a request for a yahoo api request to return whoid. But I can not generate XML for the request, the error is not displayed.
private string getWOEID()
{
string woeID = "";
String reqUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22farnborough%2Champshire%2Cuk%22&format=xml";
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(reqUrl);
WebResponse resp = wr.GetResponse();
Stream str = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(reader);
XDocument doc = XDocument.Parse(xmldoc.ToString());
woeID = doc.Descendants()
.Where(element => element.Name == "woeid")
.FirstOrDefault().Value;
return woeID;
}
Is there a better / easier way to generate an XML document from the response?
Many thanks,
source
share