Foros del Web » Programando para Internet » Javascript »

analizar xml de yahoo weather

Estas en el tema de analizar xml de yahoo weather en el foro de Javascript en Foros del Web. Estoy intentando analizar con javascript el xml de yahoo weather. Este es el xml de yahoo que se obtiene en esta direccion (debajo pongo el ...
  #1 (permalink)  
Antiguo 07/12/2008, 12:16
 
Fecha de Ingreso: julio-2003
Mensajes: 11
Antigüedad: 20 años, 9 meses
Puntos: 0
Pregunta analizar xml de yahoo weather

Estoy intentando analizar con javascript el xml de yahoo weather. Este es el xml de yahoo que se obtiene en esta direccion (debajo pongo el código para analizar el xml y los errores) http://weather.yahooapis.com/forecastrss?u=c&p=SPXX0183

xml de yahoo >>>>>>>

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>

<title>Yahoo! Weather - Salou, SP</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Salou__SP/*http://weather.yahoo.com/forecast/SPXX0183_c.html</link>
<description>Yahoo! Weather for Salou, SP</description>
<language>en-us</language>
<lastBuildDate>Sun, 07 Dec 2008 9:00 am CET</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Salou" region="" country="SP"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/>
<yweather:wind chill="9" direction="330" speed="8.05" />
<yweather:atmosphere humidity="82" visibility="9.99" pressure="0" rising="1" />
<yweather:astronomy sunrise="8:07 am" sunset="5:27 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Salou, SP at 9:00 am CET</title>
<geo:lat>41.07</geo:lat>
<geo:long>1.13</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Salou__SP/*http://weather.yahoo.com/forecast/SPXX0183_c.html</link>
<pubDate>Sun, 07 Dec 2008 9:00 am CET</pubDate>
<yweather:condition text="Fair" code="34" temp="10" date="Sun, 07 Dec 2008 9:00 am CET" />
<description><![CDATA[
<img src="http://l.yimg.com/us.yimg.com/i/us/we/52/34.gif"/><br />
<b>Current Conditions:</b><br />
Fair, 10 C<BR />
<BR /><b>Forecast:</b><BR />
Sun - Foggy. High: 15 Low: 7<br />
Mon - Foggy. High: 14 Low: 6<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Salou__SP/*http://weather.yahoo.com/forecast/SPXX0183_c.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Sun" date="7 Dec 2008" low="7" high="15" text="Foggy" code="20" />
<yweather:forecast day="Mon" date="8 Dec 2008" low="6" high="14" text="Foggy" code="20" />
<guid isPermaLink="false">SPXX0183_2008_12_07_9_00_CET</guid>
</item>
</channel>
</rss><!-- api3.weather.ac4.yahoo.com uncompressed/chunked Sun Dec 7 00:27:43 PST 2008 -->
/chunked Sat Dec 6 16:38:39 PST 2008 -->
8 -->


-----------------------------------
página html para analizar el xml de yahoo >>>>>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ejemplo de Obtener Temperatura via XML</title>
<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument(""," ",null);
}
catch(e) {alert(e.message)}
}

xmlDoc.async=false;
xmlDoc.load("weather.xml");

temperatura=xmlDoc.getElementsByTagName("yweather: condition")[0].Attributes[2].nodeValue;

document.getElementById("temp").innerHTML=temperat ura;

}

</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>
<body onload="parseXML()">
<b>Temperatura:</b> <span id="temp"></span><br />

</body>
</html>

---------
Todas las veces me da un error, en internet explorer error en la línea 23 "se requiere un objeto". En firefox con el firebug también en la línea 23 "xmlDoc.getElementsByTagName("yweather:conditi on")[0] is undefined"

muchas gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:50.