CALL XML

Tagged:

Currently contains 5 posts

Avatar

November 28, 2016 13:05

Ruben vazquez

http://api.weatherunlocked.com/api/forecast/42.21,-8.81?Accept=text/xml&lang=es&app_id=*********&app_key=***********************

Hello, I’m trying to call xml for php with no response. I’ve tried putting “Accept = text / xml” but I do not see any changes. I have also tried without it.

The code I use is this because I understand that what is displayed is XML?

$Zona1H = “http://api.weatherunlocked.com/api/forecast/42.21,-8.81?lang=es&app_id=******&app_key=***************************”;
// ZONA-1F
$Zona1H = simplexml_load_file($xmlZona1F);
$dia1_Zona_1H = $Zona1H→Day0→windspd_max_mph;
echo $dia1_Zona_1H;
the Day is “Day0
Thank you

Avatar

November 28, 2016 14:06

Marco

Hi,

The output format must be specified in the “Accept” header and not in the request URL.

here’s an example using php:
http://stackoverflow.com/a/8693175

Cheers,

Marco

Avatar

November 28, 2016 15:07

Ruben vazquez

Thank you very much marco. What returns me is an xml without structure. How do I go about it or organize it?

SimpleXMLElement Object ( [Days] => SimpleXMLElement Object ( [Day] => Array ( 0 => SimpleXMLElement Object ( [date] => 28/11/2016 [sunrise_time] => 08:41 [sunset_time] => 18:05 [moonrise_time] => 07:24 [moonset_time] => 17:54 [temp_max_c] => 15 [temp_max_f] => 59 [temp_min_c] => 10 [temp_min_f] => 50 [precip_total_mm] => 0 [precip_total_in] => 0 [rain_total_mm] => 0 [rain_total_in] => 0 [snow_total_mm] => 0 [snow_total_in] => 0 [prob_precip_pct] => 15 [humid_max_pct] => 81 [humid_min_pct] => 66 [windspd_max_mph] => 5 [windspd_max_kmh] => 8 [windspd_max_kts] => 4 [windspd_max_ms] => 2.3 [windgst_max_mph] => 11 [windgst_max_kmh] => 18 [windgst_max_kts] => 10 [windgst_max_ms] => 4.9 [slp_max_in] => 30.08 [slp_max_mb] => 1015.9 [slp_min_in] => 29.98 [slp_min_mb] => 1012.3 [Timeframes] => SimpleXMLElement Object ( [Timeframe] => Array ( 0 => SimpleXMLElement Object ( [date] => 28/11/2016 [time] => 100 [utcdate] => 28/11/2016 [utctime] => 0 [wx_desc] => Despejado [wx_code] => 0 [wx_icon] => Clear.gif [temp_c] => 10.6 [temp_f] => 51.1 [feelslike_c] => 9.8 [feelslike_f] => 49.6 [winddir_deg] => 99 [winddir_compass] => E [windspd_mph] => 5 [windspd_kmh] => 8 [windspd_kts] => 4 [windspd_ms] => 2.2 [windgst_mph] => 10 [windgst_kmh] => 16 [windgst_kts] => 9 [windgst_ms] => 4.4 [cloud_low_pct] => 0 [cloud_mid_pct] => 21 [cloud_high_pct] => 14 [cloudtotal_pct] => 22 [precip_mm] => 0 [precip_in] => 0 [rain_mm] =>

Avatar

November 28, 2016 16:30

John Armstrong

Hi Ruben,

The simplexml_load_file function parses the xml response into a data structure.

You should be able to get data following some of these examples:
http://www.w3schools.com/php/php_xml_simplexml_get.asp
http://php.net/manual/en/simplexml.examples-basic.php

Cheers,

Marco

Avatar

November 28, 2016 22:26

Ruben vazquez

Ok, Thank you Marco!!

Reply to thread
  1. If you're human, leave this field empty.