thejargen Posted January 14, 2013 Share Posted January 14, 2013 Hi, Im making a script which will parse a XML feed. The problem is i cant work out a way to count the attributes (I believe they are called attributes), for example: <STOCK Color="Black" Size="Small">In Stock</STOCK> Has 2 Attributes <STOCK Color="Black" Size="Small" Animal="Dog">In Stock</STOCK> Has 3 Attributes But i cant find any way to count them. I am using SimpleXML Any help? Thanks. Link to comment https://forums.phpfreaks.com/topic/273142-counting-attributes/ Share on other sites More sharing options...
devWhiz Posted January 14, 2013 Share Posted January 14, 2013 SimpleXMLElement::attributes should be what you need.. If you want to post the xml, I may be able to help you out more. Link to comment https://forums.phpfreaks.com/topic/273142-counting-attributes/#findComment-1405569 Share on other sites More sharing options...
The Letter E Posted January 15, 2013 Share Posted January 15, 2013 You should be able to do something like: $attribute_count = count($xml->attributes()); not tested Link to comment https://forums.phpfreaks.com/topic/273142-counting-attributes/#findComment-1405736 Share on other sites More sharing options...
thejargen Posted January 17, 2013 Author Share Posted January 17, 2013 You should be able to do something like: $attribute_count = count($xml->attributes()); not tested That worked. Thanks! Link to comment https://forums.phpfreaks.com/topic/273142-counting-attributes/#findComment-1406411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.