Friday, 6 February 2015

count xml elements/nodes using SimpleXML



this could be duplicate, but I found nothing useful so far.


I'm trying to count nodes/childs of XML file using simplexml.


I've tried this.



$xml = simplexml_load_file("./file.xml");
echo count($xml->rss->channel->item);


and



echo count($xml->item);


but just outputting 0.


here is snapshot of XML



<?xml version="1.0"?>
<rss xmlns:xsd="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:g="http://ift.tt/15FVsV8" version="2.0">
<channel>
<item>
<title>PUDRA Pudra Ceket Ceket</title>
<link>http://ift.tt/1zGULXt;
<description>36 pudra pudra ceket ıw6140005046 ipekyol ceket kadın</description>
<g:urunid>1423905</g:urunid>
<g:id>1423905_14</g:id>
</item>
<item>
....
</item>

No comments:

Post a Comment