extract XML data using attributes from a URL php -


i have url response xml data

<account account="ihs" timezone="gmt+05:30"> <description>the indian heights school</description> <device id="09647"> <description>dl1pd0228</description> <eventdata device="09647"> <timestamp epoch="1416968997">2014/11/26 07:59:57 gmt+05:30</timestamp> <statuscode code="0xf401">ignition_on</statuscode> <gpspoint>28.56262,77.05264</gpspoint> <speed units="km/h">0.0</speed> <odometer units="km">4390.1</odometer> <geozone index="0">tihs</geozone> <address>the indian heights school</address> </eventdata> </device> <device id="8786"> <description>dl1vc1750</description> <eventdata device="8786"> <timestamp epoch="1416989072">2014/11/26 13:34:32 gmt+05:30</timestamp> <statuscode code="0xf020">location</statuscode> <gpspoint>28.56234,77.05284</gpspoint> <speed units="km/h">0.0</speed> <odometer units="km">6154.6</odometer> <geozone index="0">tihs</geozone> <address>the indian heights school</address> </eventdata> </device> 

i want extract <description> tage xml using php please me

i using curl, simplexmlloadfile, simplexmlloadstring doing

 $ch = curl_init(); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_url, $url);    // url contents  $data = curl_exec($ch); // execute curl request curl_close($ch);  $xml = simplexml_load_string($data); print_r($xml) 

and

     simplexmlelement object (     [@attributes] => array         (             [account] => ihs             [timezone] => gmt+05:30         )      [description] => simplexmlelement object         (         )      [device] => array         (             [0] => simplexmlelement object                 (                     [@attributes] => array                         (                             [id] => 09647                         )                      [description] => simplexmlelement object                         (                         )                      [eventdata] => simplexmlelement object                         (                             [@attributes] => array                                 (                                     [device] => 09647                                 )                              [timestamp] => 2014/11/26 07:59:57 gmt+05:30                             [statuscode] => simplexmlelement object                                 (                                     [@attributes] => array                                         (                                             [code] => 0xf401                                         )                                  )                              [gpspoint] => 28.56262,77.05264                             [speed] => 0.0                             [odometer] => 4390.1                             [geozone] => tihs                             [address] => simplexmlelement object                                 (                                 )                          )                  )              [1] => simplexmlelement object                 (                     [@attributes] => array                         (                             [id] => 8786                         )                      [description] => simplexmlelement object                         (                         )                      [eventdata] => simplexmlelement object                         (                             [@attributes] => array                                 (                                     [device] => 8786                                 )                              [timestamp] => 2014/11/26 14:45:33 gmt+05:30                             [statuscode] => simplexmlelement object                                 (                                     [@attributes] => array                                         (                                             [code] => 0xf113                                         )                                  )                              [gpspoint] => 28.61029,76.98159                             [speed] => 0.0                             [odometer] => 6155.0                         )                  ) 

in front of description have noting , dont know how can extract

you need stay case sensitive:

echo $xml->description; 

also foreach:

foreach($xml->device $device) {     echo $device->description; } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -