I have this XML
<STOREITEMS>
<CREATED value="Tue Oct 9 5:30:01 BST 2012">
<CATEGORY id="442" name="Hen And Stag Nights"></CATEGORY>
<CATEGORY id="69" name="Games"></CATEGORY>
<CATEGORY id="252" name="Love Zone"></CATEGORY>
<CATEGORY id="202" name="Spotlight Items"></CATEGORY>
</CREATED>
</STOREITEMS>
I need to get the Category – name attribute with PHP
So far I have this
$xml = simplexml_load_file("http://www.dropshipping.co.uk/catalog/xml_id_multi_info.xml");
foreach($xml->CATEGORY['name']->attributes() as $category)
{
echo $category;
}
This however returns Fatal error: Call to a member function attributes() on a non-object
Any ideas?
Thank you.
The
CATEGORYnodes are nested inside theCREATEDnode, so you’d need to access it there, and accessingCATEGORY['name']->attributes()makes no sense, since that would try to access non-existent attributes on thenameattribute of the firstCATEGORYnode.So do you want to retreive the name attribute values of all
CATEGORYnodes, or allCATEGORYnodes, or maybe only thoseCATEGORYnodes that have anameattribute?All
CATEGORYnodes:Only the
CATEGORYnodes name attributes:Only the
CATEGORYnodes that have a name attribute: