problems geting values from xml

Im trying to get some values from the below xml feed

    <?xml version="1.0" ?>
<SEARCH>
  <LOCATION>
   <NAME>Terrance</NAME>
   <COUNTRY>USA</COUNTRY>
  </LOCATION>
<FOUND>
    <TOTALOFOUND>
    <TOTAL>3</TOTAL>
    </TOTALOFOUND>
  <PLACE>
      <ADDRESS>IL Road</ADDRESS>
      <NAME>shop1</NAME>
      <POSTCODE>5</POSTCODE>
    <CATIM>
      <SMALL>ILR.jpg</SMALL>
      <MEDIUM>ILR1.jpg</MEDIUM>
      <DESCRIPTION>feeds</DESCRIPTION>
    </CATIM>
    <BUILD>this is the first test xml feed</BUILD>
    <ID>1235</ID>
    <DIST>
     <LAT>25</LAT>
     <LONG>547</LONG>
   </DIST>
  </PLACE>
  <PLACE>
      <ADDRESS>Peter Road</ADDRESS>
      <NAME>textas</NAME>
      <POSTCODE>987</POSTCODE>
    <CATIM>
      <SMALL>test.jpg</SMALL>
      <MEDIUM>test1.jpg</MEDIUM>
      <DESCRIPTION>feeds new</DESCRIPTION>
    </CATIM>
    <BUILD>this is the second test xml feed</BUILD>
    <ID>1235</ID>
    <DIST>
     <LAT>25</LAT>
     <LONG>547</LONG>
   </DIST>
  </PLACE>
   <PLACE>
      <ADDRESS>Thsi is the 3rd st</ADDRESS>
      <NAME>utah</NAME>
      <POSTCODE>9117</POSTCODE>
    <CATIM>
      <SMALL>utah.jpg</SMALL>
      <MEDIUM>utah1.jpg</MEDIUM>
      <DESCRIPTION>feeds new 3</DESCRIPTION>
    </CATIM>
    <BUILD>this is the third test xml feed</BUILD>
    <ID>000000</ID>
    <DIST>
     <LAT>000</LAT>
     <LONG>54000</LONG>
   </DIST>
  </PLACE>
 </FOUND>
</SEARCH>

I have used the following code to grab the values

<?php
strings = file_get_contents("feed.xml");
$xml=simplexml_load_string($strings);

foreach ($xml as $place)
{
echo "Total : ".$place->TOTALOFOUND->TOTAL."<br />";
echo "address: ".$place->PLACE->ADDRESS."<br />";
echo "Name : ".$place->PLACE->NAME."<br />";
echo "post code: ".$place->PLACE->POSTCODE."<br />";
echo "Small image: ".$place->PLACE->CATIM->SMALL."<br />";
echo "Medium Image: ".$place->PLACE->CATIM->MEDIUM."<br />";
echo "Descripton: ".$place->PLACE->CATIM->DESCRIPTION."<br />";
echo "Office ID: ".$place->PLACE->ID."<br />";
echo "Cord Lat: ".$place->PLACE->DIST->LAT."<br />";
echo "Cord Long: ".$place->PLACE->DIST->LONG."<br />"."<br />";
}
?>

the problem is that although i have 3 records in the xml it shows only the first results. and at the beginning it gives the below error. Can some one please help me

Total :
address:
Name :
post code:

Notice: Trying to get property of non-object in C:\wamp\www\site\test.php on line 16
Small image:

Notice: Trying to get property of non-object in C:\wamp\www\site\test.php on line 17
Medium Image:
Descripton:
Office ID:

Notice: Trying to get property of non-object in C:\wamp\www\site\test.php on line 20
Cord Lat:

Notice: Trying to get property of non-object in C:\wamp\www\site\test.php on line 21
Cord Long:

Total : 3
address: IL Road
Name : shop1
post code: 5
Small image: ILR.jpg
Medium Image: ILR1.jpg
Descripton:
Office ID: 1235
Cord Lat: 25
Cord Long: 547

any help will be much appreciated

thanks

Answers


You have to look at the structure of the XML more closely and access the nodes in the appropriate way base on their hierarchy.

echo "Total : ".$xml->FOUND->TOTALOFOUND->TOTAL."<br />";
foreach ( $xml->FOUND->PLACE as $place )
{
  echo "address: ".$place->ADDRESS."<br />";
  echo "Name : ".$place->NAME."<br />";
  echo "post code: ".$place->POSTCODE."<br />";
  echo "Small image: ".$place->CATIM->SMALL."<br />";
  echo "Medium Image: ".$place->CATIM->MEDIUM."<br />";
  echo "Descripton: ".$place->CATIM->DESCRIPTION."<br />";
  echo "Office ID: ".$place->ID."<br />";
  echo "Cord Lat: ".$place->DIST->LAT."<br />";
  echo "Cord Long: ".$place->DIST->LONG."<br />"."<br />";
}

Need Your Help

refreshing knockout model after committing changes to upshot datasource

knockout.js asp.net-mvc-4 upshot

I followed the MVC4 SPA walkthrough example and created a simple application where I pull down a list of 10 topics, let users mark them as safe or bad, and then save changes. Now, when users save

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.