title: Php Recursive function to parse nested xml tags
body: <p>I'm trying to parse this XML structure but can't find a way to parse "n"-deep nested tags using recursion.
  The xml structure:</p>
  
  <pre><code>&lt;plist version="1.0"&gt;
      &lt;key&gt;1.1.1&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;nag&lt;/key&gt;
          &lt;integer&gt;1&lt;/integer&gt;
      &lt;/dict&gt;
  
      &lt;key&gt;2.2.2&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;nag&lt;/key&gt;
          &lt;integer&gt;1&lt;/integer&gt;
      &lt;/dict&gt;
  
      &lt;key&gt;3.3.3&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;show_upgrade_button&lt;/key&gt;
          &lt;integer&gt;0&lt;/integer&gt;
  
          &lt;key&gt;nag_startup&lt;/key&gt;
          &lt;dict&gt;
              &lt;key&gt;nag_gameover&lt;/key&gt;
              &lt;integer&gt;3&lt;/integer&gt;
          &lt;/dict&gt;
  
          &lt;key&gt;my_stuff&lt;/key&gt;
          &lt;string&gt;1=cb 2=rm 3=cb+rm =leave banner ads off&lt;/string&gt;
  
      &lt;/dict&gt;
  
      &lt;key&gt;4.4.4&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;nag&lt;/key&gt;
          &lt;integer&gt;1&lt;/integer&gt;
      &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>The nodes are matched <code>key</code> - <code>dict</code> being the key node a version number for the data inside the <code>dict</code> node but the xml structure has arbrittrary <code>dict</code> nesting as you can see in the above code. I've got this recursive function which accepts a <code>dict</code> node so far but I can't see the light.</p>
  
  <pre><code>&lt;? php
  function recursiveNodes($nodes, $arr){
          $count=0;
          if($nodes-&gt;hasChildNodes() === true  ){ 
  
              foreach($nodes-&gt;childNodes as $node){
  
                  $temp = array();
                  if($node-&gt;nodeName === 'key'){
  
                      $temp['key_name'] = $node-&gt;nodeValue;
                      if($node-&gt;nextSibling-&gt;nodeName !== 'dict'){
                          $sibling = $node-&gt;nextSibling;                      
                          $temp['type_name'] = $sibling -&gt;nodeName;
                          $temp['value_name'] = $sibling -&gt;nodeValue;
                      }
                      if($sibling-&gt;nodeName === 'dict'){
                      return recursiveNodes($sibling, $arr[$count++][]=$temp);
                  }   
                  }
  
              }
  
          }
              return $arr;
      }
      ?&gt;
  </code></pre>