Reputation: 13
I have following XML (source.xml):
<SHOP>
<SHOPITEM>
<ITEM_ID>3664</ITEM_ID>
<PRODUCT>Product n.1</PRODUCT>
<PRODUCT_NAME>Product n.1</PRODUCT_NAME>
<VARIANT_NAME/>
<MANUFACTURER>Jeffrey</MANUFACTURER>
<CODE>ABC123</CODE>
<EAN>123456789</EAN>
<DESCRIPTION>
Maybe later...
</DESCRIPTION>
<DESCRIPTION_HTML/>
<CATEGORIES>
<CATEGORY id="1" parent_id="0">ABx</CATEGORY>
</CATEGORIES>
</SHOPITEM>
<SHOPITEM>
...etc
And following code:
$xml = simplexml_load_file("source.xml", NULL, LIBXML_NOCDATA);
foreach ($xml->shopitem as $shopitem) {
echo $shopitem->item_id;
}
Unfortunately, it doesn't work. Even if I put echo 'a'; into foreach cycle, nothing appears. XML is valid. Tried var_dump($xml) and the XML looks to be loaded correctly. What is wrong? Thank you.
Upvotes: 0
Views: 154
Reputation: 1583
$xml = simplexml_load_file("source.xml", NULL, LIBXML_NOCDATA);
foreach ($xml->SHOPITEM as $shopitem) {
echo $shopitem->ITEM_ID;
}
Upvotes: 1