Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/01/2012, 06:16
arros
 
Fecha de Ingreso: noviembre-2009
Mensajes: 535
Antigüedad: 14 años, 6 meses
Puntos: 25
Respuesta: attributes img CDATA xml php

en primero lugar agradezco tu respuesta aun lo estoy mirando...
aqui pongo todo mi ejemplo:
lo que quiero es mostrar el tiempo de yahoo.waeter en mi pagina la respuesta es de formato xml en esto no tengo ninguna problema, pero lo que quiero es mostrar solo la imagen del tiempo y la temperatura sin logo de yahoo ni otra cosa
codigo xml
Código XML:
Ver original
  1. <rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
  2. <channel>
  3. <title>Yahoo! Weather - Sunnyvale, CA</title>
  4. <link>...</link>
  5. <description>Yahoo! Weather for Sunnyvale, CA</description>
  6. <language>en-us</language>
  7. <lastBuildDate>Mon, 23 Jan 2012 10:02 am PST</lastBuildDate>
  8. <ttl>60</ttl>
  9. <yweather:location city="Sunnyvale" region="CA" country="United States"/>
  10. <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
  11. <yweather:wind chill="54" direction="260" speed="9"/>
  12. <yweather:atmosphere humidity="82" visibility="10" pressure="29.88" rising="0"/>
  13. <yweather:astronomy sunrise="7:18 am" sunset="5:21 pm"/>
  14. <image>...</image>
  15. <item>
  16. <title>Conditions for Sunnyvale, CA at 10:02 am PST</title>
  17. <geo:lat>37.37</geo:lat>
  18. <geo:long>-122.04</geo:long>
  19. <link>...</link>
  20. <pubDate>Mon, 23 Jan 2012 10:02 am PST</pubDate>
  21. <yweather:condition text="Cloudy" code="26" temp="54" date="Mon, 23 Jan 2012 10:02 am PST"/>
  22. <description>
  23. <![CDATA[
  24. <img src="http://l.yimg.com/a/i/us/we/52/26.gif"/><br /> <b>Current Conditions:</b><br /> Cloudy, 54 F<BR /> <BR /><b>Forecast:</b><BR /> Mon - AM Rain. High: 58 Low: 44<br /> Tue - Partly Cloudy. High: 63 Low: 45<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
  25. ]]>
  26. </description>
  27. <yweather:forecast day="Mon" date="23 Jan 2012" low="44" high="58" text="AM Rain" code="12"/>
  28. <yweather:forecast day="Tue" date="24 Jan 2012" low="45" high="63" text="Partly Cloudy" code="30"/>
  29. <guid isPermaLink="false">USCA1116_2012_01_24_7_00_PST</guid>
  30. </item>
  31. </channel>
  32. </rss>
codigo php

Código PHP:
Ver original
  1. $xml_file = 'http://weather.yahooapis.com/forecastrss?w=2502265';
  2. // The XML data file with whitespace such as tabs
  3. // Load xml data.
  4. $xml_f = simplexml_load_string($xml_file);
  5. $x = $xml_file->channel->item->description;
  6. $xml = file_get_contents($xml_file);
  7. // Strip whitespace between xml tags
  8. $xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml);
  9. // Convert CDATA into xml nodes.
  10. $result = simplexml_load_string($xml,$x, LIBXML_NOCDATA);
  11. // Return JSON.
  12. //var_dump(json_encode($xml));
  13. foreach($result->channel->item->description as $e){
  14.     echo $e;
y desta forma consigo mostrar el CDATA pero en formato html y lo que quiero solo attr de img no mas cosas
gracias
__________________
cada vez que aprendes algo te crees que no sabes nada