Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems geting values from xml
    text
    copied!<p>Im trying to get some values from the below xml feed</p> <pre><code> &lt;?xml version="1.0" ?&gt; &lt;SEARCH&gt; &lt;LOCATION&gt; &lt;NAME&gt;Terrance&lt;/NAME&gt; &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt; &lt;/LOCATION&gt; &lt;FOUND&gt; &lt;TOTALOFOUND&gt; &lt;TOTAL&gt;3&lt;/TOTAL&gt; &lt;/TOTALOFOUND&gt; &lt;PLACE&gt; &lt;ADDRESS&gt;IL Road&lt;/ADDRESS&gt; &lt;NAME&gt;shop1&lt;/NAME&gt; &lt;POSTCODE&gt;5&lt;/POSTCODE&gt; &lt;CATIM&gt; &lt;SMALL&gt;ILR.jpg&lt;/SMALL&gt; &lt;MEDIUM&gt;ILR1.jpg&lt;/MEDIUM&gt; &lt;DESCRIPTION&gt;feeds&lt;/DESCRIPTION&gt; &lt;/CATIM&gt; &lt;BUILD&gt;this is the first test xml feed&lt;/BUILD&gt; &lt;ID&gt;1235&lt;/ID&gt; &lt;DIST&gt; &lt;LAT&gt;25&lt;/LAT&gt; &lt;LONG&gt;547&lt;/LONG&gt; &lt;/DIST&gt; &lt;/PLACE&gt; &lt;PLACE&gt; &lt;ADDRESS&gt;Peter Road&lt;/ADDRESS&gt; &lt;NAME&gt;textas&lt;/NAME&gt; &lt;POSTCODE&gt;987&lt;/POSTCODE&gt; &lt;CATIM&gt; &lt;SMALL&gt;test.jpg&lt;/SMALL&gt; &lt;MEDIUM&gt;test1.jpg&lt;/MEDIUM&gt; &lt;DESCRIPTION&gt;feeds new&lt;/DESCRIPTION&gt; &lt;/CATIM&gt; &lt;BUILD&gt;this is the second test xml feed&lt;/BUILD&gt; &lt;ID&gt;1235&lt;/ID&gt; &lt;DIST&gt; &lt;LAT&gt;25&lt;/LAT&gt; &lt;LONG&gt;547&lt;/LONG&gt; &lt;/DIST&gt; &lt;/PLACE&gt; &lt;PLACE&gt; &lt;ADDRESS&gt;Thsi is the 3rd st&lt;/ADDRESS&gt; &lt;NAME&gt;utah&lt;/NAME&gt; &lt;POSTCODE&gt;9117&lt;/POSTCODE&gt; &lt;CATIM&gt; &lt;SMALL&gt;utah.jpg&lt;/SMALL&gt; &lt;MEDIUM&gt;utah1.jpg&lt;/MEDIUM&gt; &lt;DESCRIPTION&gt;feeds new 3&lt;/DESCRIPTION&gt; &lt;/CATIM&gt; &lt;BUILD&gt;this is the third test xml feed&lt;/BUILD&gt; &lt;ID&gt;000000&lt;/ID&gt; &lt;DIST&gt; &lt;LAT&gt;000&lt;/LAT&gt; &lt;LONG&gt;54000&lt;/LONG&gt; &lt;/DIST&gt; &lt;/PLACE&gt; &lt;/FOUND&gt; &lt;/SEARCH&gt; </code></pre> <p>I have used the following code to grab the values</p> <pre><code>&lt;?php strings = file_get_contents("feed.xml"); $xml=simplexml_load_string($strings); foreach ($xml as $place) { echo "Total : ".$place-&gt;TOTALOFOUND-&gt;TOTAL."&lt;br /&gt;"; echo "address: ".$place-&gt;PLACE-&gt;ADDRESS."&lt;br /&gt;"; echo "Name : ".$place-&gt;PLACE-&gt;NAME."&lt;br /&gt;"; echo "post code: ".$place-&gt;PLACE-&gt;POSTCODE."&lt;br /&gt;"; echo "Small image: ".$place-&gt;PLACE-&gt;CATIM-&gt;SMALL."&lt;br /&gt;"; echo "Medium Image: ".$place-&gt;PLACE-&gt;CATIM-&gt;MEDIUM."&lt;br /&gt;"; echo "Descripton: ".$place-&gt;PLACE-&gt;CATIM-&gt;DESCRIPTION."&lt;br /&gt;"; echo "Office ID: ".$place-&gt;PLACE-&gt;ID."&lt;br /&gt;"; echo "Cord Lat: ".$place-&gt;PLACE-&gt;DIST-&gt;LAT."&lt;br /&gt;"; echo "Cord Long: ".$place-&gt;PLACE-&gt;DIST-&gt;LONG."&lt;br /&gt;"."&lt;br /&gt;"; } ?&gt; </code></pre> <p>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</p> <pre><code>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 </code></pre> <p>any help will be much appreciated</p> <p>thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload