我目前正在使用C#进行小型天气应用。为此,我需要从此xml文件中提取数据:http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22london%22&format=xml
在这种特定情况下,我需要第一个/ query / results / place / woeid节点的值。我一直在四处寻找并尝试了许多不同的方法,但没有设法获得任何这些方法的价值。我目前的代码如下:
console.log( arr.join('-') );
// "8" >> "8"
// "04564" >> "045-64"
// "8213221" >> "821-322-1"
// "263290004" >> "263-290-004"
我刚开始学习C#所以我可能会犯一些愚蠢的错误。不过,我真的很感激任何帮助。
答案 0 :(得分:0)
您可以使用XDocument
string query = String.Format("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22london%22&format=xml");
XDocument xml = XDocument.Load(query);
XNamespace ns = "http://where.yahooapis.com/v1/schema.rng";
var woeid = xml.Element("query").Element("results").Elements(ns + "place").FirstOrDefault().Element(ns +"woeid").Value;
确保检查XDocuments中是否有任何元素