0
我正在尝试使用JavaScript从雅虎天气中提取数据(例如http://weather.yahooapis.com/forecastrss?w=9807&u=c)。查找未关闭的XML节点(雅虎天气)
我看了其他线程包括Trying to pull in elements from Yahoo Weather XML和Trying to retrieve yahoo weather using jquery/php/xml和Parsing XML namespaces?
我已经成立了一个代理我的服务器上,以便阿贾克斯可以抓取文件,它开辟了罚款(比如我可以写documentElement )。但是,我有问题,抓住了标记,如
<yweather:condition text="Mostly Cloudy" code="28" temp="5" date="Mon, 06 Feb 2012 10:00 am PST"/>
我想这是因为它不是像
<ttl>60</ttl>
结束标记谁能帮助我?使用Javascript 谢谢
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xmlDoc, "text/xml");
alert(xmlDoc.getElementsByTagName("ttl")[0].childNodes[0].nodeValue); //works
alert(xmlDoc.getElementsByTagName("yweather:location")[0].childNodes[0].getAttribute("city")); //doesn't
另外,该标签/元素已关闭。这就是solidus(标签末尾的'/')。 – 2012-02-06 20:12:35