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