Search code examples
phprsssimplexml

Rss tag as SimpleXMLElement children count is zero


Simply I have a function which gets tag names of has children tags:

$tags = [];
function getHasChildTags($xml){

    global $tags;
    if(count($xml->children()) > 0){
    
        $tags[$xml->getName()] = $xml->getName();
    
    foreach($xml->children() as $child){
        getHasChildTags($child);
    }
}

}

But in an rss xml that has a blueprint of below "item" tag's children count is seen zero (0) and so it is not added to $tags global array.

<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
 <channel>
  <item>
   <g:id>14</g:id>
   <g:title>Oversize Basic T-Shirt - Mor - S/M</g:title>
   ...
  </item>
 </channel>
</rss>

Thanks in advice.


Solution

  • $xml->children('g', true);
    

    That is the solution. I found it while trying.