Foros del Web » Programación para mayores de 30 ;) » Programación General »

analizar xml de yahoo weather

Estas en el tema de analizar xml de yahoo weather en el foro de Programación General 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 08/12/2008, 02:04
 
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 >>>>>>>
Código xml:
Ver original
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2. <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#">
  3. <channel>
  4.  
  5. <title>Yahoo! Weather - Salou, SP</title>
  6. <link>http://us.rd.yahoo.com/dailynews/rss/weather/Salou__SP/*http://weather.yahoo.com/forecast/SPXX0183_c.html</link>
  7. <description>Yahoo! Weather for Salou, SP</description>
  8. <language>en-us</language>
  9. <lastBuildDate>Sun, 07 Dec 2008 9:00 am CET</lastBuildDate>
  10. <ttl>60</ttl>
  11. <yweather:location city="Salou" region="" country="SP"/>
  12. <yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/>
  13. <yweather:wind chill="9" direction="330" speed="8.05" />
  14. <yweather:atmosphere humidity="82" visibility="9.99" pressure="0" rising="1" />
  15. <yweather:astronomy sunrise="8:07 am" sunset="5:27 pm"/>
  16. <image>
  17. <title>Yahoo! Weather</title>
  18. <width>142</width>
  19. <height>18</height>
  20. <link>http://weather.yahoo.com</link>
  21. <url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
  22. </image>
  23. <item>
  24. <title>Conditions for Salou, SP at 9:00 am CET</title>
  25. <geo:lat>41.07</geo:lat>
  26. <geo:long>1.13</geo:long>
  27. <link>http://us.rd.yahoo.com/dailynews/rss/weather/Salou__SP/*http://weather.yahoo.com/forecast/SPXX0183_c.html</link>
  28. <pubDate>Sun, 07 Dec 2008 9:00 am CET</pubDate>
  29. <yweather:condition text="Fair" code="34" temp="10" date="Sun, 07 Dec 2008 9:00 am CET" />
  30. <description><![CDATA[
  31. <img src="http://l.yimg.com/us.yimg.com/i/us/we/52/34.gif"/><br />
  32. <b>Current Conditions:</b><br />
  33. Fair, 10 C<BR />
  34. <BR /><b>Forecast:</b><BR />
  35. Sun - Foggy. High: 15 Low: 7<br />
  36. Mon - Foggy. High: 14 Low: 6<br />
  37. <br />
  38. <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/>
  39. (provided by The Weather Channel)<br/>
  40. ]]></description>
  41. <yweather:forecast day="Sun" date="7 Dec 2008" low="7" high="15" text="Foggy" code="20" />
  42. <yweather:forecast day="Mon" date="8 Dec 2008" low="6" high="14" text="Foggy" code="20" />
  43. <guid isPermaLink="false">SPXX0183_2008_12_07_9_00_CET</guid>
  44. </item>
  45. </channel>
  46. </rss><!-- api3.weather.ac4.yahoo.com uncompressed/chunked Sun Dec 7 00:27:43 PST 2008 -->
  47. /chunked Sat Dec 6 16:38:39 PST 2008 -->
  48. 8 -->

-----------------------------------
página html para analizar el xml de yahoo >>>>>
Código html:
Ver original
  1. <!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">
  2. <title>Ejemplo de Obtener Temperatura via XML</title>
  3. <script type="text/javascript">
  4. function parseXML()
  5. {
  6. try //Internet Explorer
  7. {
  8. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  9. }
  10. catch(e)
  11. {
  12. try //Firefox, Mozilla, Opera, etc.
  13. {
  14. xmlDoc=document.implementation.createDocument(""," ",null);
  15. }
  16. catch(e) {alert(e.message)}
  17. }
  18.  
  19. xmlDoc.async=false;
  20. xmlDoc.load("weather.xml");
  21.  
  22. temperatura=xmlDoc.getElementsByTagName("yweather: condition")[0].Attributes[2].nodeValue;
  23.  
  24. document.getElementById("temp").innerHTML=temperat ura;
  25.  
  26. }
  27.  
  28.  
  29. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>
  30. <body onload="parseXML()">
  31. <b>Temperatura:</b> <span id="temp"></span><br />
  32.  
  33. </body>
  34. </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

Última edición por jam1138; 08/12/2008 a las 11:08 Razón: Coloreo código
  #2 (permalink)  
Antiguo 08/12/2008, 11:23
Avatar de jam1138
/** @package Moderador */
 
Fecha de Ingreso: julio-2004
Ubicación: sèveR led onieR lE
Mensajes: 9.368
Antigüedad: 19 años, 9 meses
Puntos: 102
Respuesta: analizar xml de yahoo weather

Por favor, evita duplicar temas. Va contra las normas del foro.

Continúa en: http://www.forosdelweb.com/f13/anali...eather-651864/
__________________
٩(͡๏̯͡๏)۶
» Cómo hacer preguntas de manera inteligente «

"100 años después, la revolución no es con armas, es intelectual y digital"
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 03:44.