PHP handling XML Feed with Simple XML -


i using uk met office api use weather information. xml layed out following:

<siterep>   <wx>     <param name="f" units="c">feels temperature</param>     <param name="g" units="mph">wind gust</param>     <param name="h" units="%">screen relative humidity</param>     <param name="t" units="c">temperature</param>     <param name="v" units="">visibility</param>     <param name="d" units="compass">wind direction</param>     <param name="s" units="mph">wind speed</param>     <param name="u" units="">max uv index</param>     <param name="w" units="">weather type</param>     <param name="pp" units="%">precipitation probability</param>   </wx> <dv datadate="2013-08-28t08:00:00z" type="forecast"> <location i="22" lat="53.5797" lon="-0.3472" name="humberside airport" country="england" continent="europe">   <period type="day" value="2013-08-28z">     <rep d="ssw" f="19" g="9" h="59" pp="0" s="4" t="20" v="vg" w="3" u="3">720</rep>    </period> </location> <location i="25" lat="53.8658" lon="-1.6606" name="leeds bradford international airport" country="england" continent="europe">   <period type="day" value="2013-08-28z">     <rep d="sw" f="17" g="11" h="72" pp="7" s="7" t="18" v="go" w="7" u="3">720</rep>   </period> </location> </dv> </siterep> 

if load xml feed using simplexml_load_file , print_r following output:

[wx] => simplexmlelement object     (         [param] => array             (                 [0] => feels temperature                 [1] => wind gust                 [2] => screen relative humidity                 [3] => temperature                 [4] => visibility                 [5] => wind direction                 [6] => wind speed                 [7] => max uv index                 [8] => weather type                 [9] => precipitation probability             )      )  [dv] => simplexmlelement object     (         [@attributes] => array             (                 [datadate] => 2013-08-28t08:00:00z                 [type] => forecast             )          [location] => array             (                 [0] => simplexmlelement object                     (                         [@attributes] => array                             (                                 [i] => 22                                 [lat] => 53.5797                                 [lon] => -0.3472                                 [name] => humberside airport                                 [country] => england                                 [continent] => europe                             )                          [period] => simplexmlelement object                             (                                 [@attributes] => array                                     (                                         [type] => day                                         [value] => 2013-08-28z                                     )                                  [rep] => 720                             )                      )                  [1] => simplexmlelement object                     (                         [@attributes] => array                             (                                 [i] => 25                                 [lat] => 53.8658                                 [lon] => -1.6606                                 [name] => leeds bradford international airport                                 [country] => england                                 [continent] => europe                             )                          [period] => simplexmlelement object                             (                                 [@attributes] => array                                     (                                         [type] => day                                         [value] => 2013-08-28z                                     )                                  [rep] => 720                             )                      ) 

my issue vital data want within rep can't seem handle when using simplexml? should way or missing something?

try 1 getting rep

$xml = simplexml_load_file('file.xml');  foreach($xml->dv->location $location) {     $att = $location->period->rep->attributes();      echo $att['d'];     echo $att['f'];     echo $att['g'];     echo $att['h'];      etc... } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -