How to Extract XML Data data using PHP?



I had gone through many stackoverfollow question regarding this , i do get partial answer for my question , for example below is XML Code



<device_lastupdate><version>1.0</version><device><id>012980000234020</id><updated_at type="dateTime">2015-01-28T10:21:50+05:30</updated_at><lat type="float">12.828383</lat><lng type="float">79.695983</lng><address>Karukinil Amarthanval Street</address><odometer type="float">12341</odometer><speed type="float">0</speed><ignition>false</ignition></device></device_lastupdate>


and here is my php code



$xml = simplexml_load_file("data.xml");
echo "<h2>".$xml->getName()."</h2><br />";

foreach($xml->children() as $device)
{
echo "BOOK : ".$device->id."<br />";
echo "Author : ".$device->updated_at." <br />";
echo "Title : ".$device->lat." <br />";
echo "Genre : ".$device->lng." <br />";
echo "Price : ".$device->address." <br />";

echo "Publish Date : ".$device->odometer." <br />";
echo "Description : ".$device->speed." <br />";
echo "Ignition:".$device->ignition."<br />";
echo "<hr/>";
}


i can get all the data's except lat,lng and address.


how to get these data's , where i am going wrong?


No comments:

Post a Comment