The file can be seen on the following URL: #
The above XML file consists of two elements which I want to be shown in order which are the “product” and “offer”.
I use SimpleXML to load the XML feed.
$text = simplexml_load_file(‘feed.xml’);
I also use foreach to show the data from the file
foreach ($text->categories->category->items->product as $product) {}
How is it possible to show the “product” and “offer” from the XML file using a for each statement or any other method?
Does
<items>only ever contain<product>and<offer>elements? If so:See http://php.net/simplexmlelement.children
If you want to be explicit about only ever getting the product/offer elements, a simple XPath expression could be employed.