I am having trouble getting all the data from my XML. Can any one shed some light please.
My XML is as follows
<storeitems>
<PRODUCT ITEM="3002074730">
<SPECIALS_ID>14713</SPECIALS_ID>
<FULL_PRICE>27.00</FULL_PRICE>
<SPECIALS_NEW_PRODUCTS_PRICE>25.65</SPECIALS_NEW_PRODUCTS_PRICE>
</PRODUCT>
<PRODUCT ITEM="SE-0088-10-3">
<SPECIALS_ID>29555</SPECIALS_ID>
<FULL_PRICE>53.99</FULL_PRICE>
<SPECIALS_NEW_PRODUCTS_PRICE>51.29</SPECIALS_NEW_PRODUCTS_PRICE>
</PRODUCT>
<storeitems>
My code is as follows
$xml = new SimpleXMLElement($data);
foreach($xml->PRODUCT as $post) {
echo $post->SPECIALS_ID .'<BR>';
echo $post->FULL_PRICE . '<BR>';
echo $post->SPECIALS_NEW_PRODUCTS_PRICE . '<BR>';
}
This does what I expect but can you assist me in getting this part of the XML to echo please
<PRODUCT ITEM="3002074730">
will print the value of your
item(first) attribute (it’s an object that does that when it’s called in a string-context).If you add more attributes and you want to get them all, you can iterate over
$post->attributes():