title: PHP: Using simplexml to loop through all levels of an XML file
body: <p>I have a function which uses simplexml to return the first level of nodes in an XML file and write it into an unordered list:</p>
  
  <pre><code>function printAssetMap() {
      $xml = simplexml_load_file(X_ASSETS);
      $assets = $xml-&gt;asset;
      $html = '&lt;ul&gt;'."\n";
      foreach ($assets as $asset) {
          $html .= '&lt;li id="asset'.$asset-&gt;asset_assetid.'"&gt;&lt;ins&gt;&amp;nbsp;&lt;/ins&gt;&lt;a href="#"&gt;'.$asset-&gt;asset_name.' ['.$asset-&gt;asset_assetid.']&lt;/a&gt;&lt;/li&gt;'."\n";
      }//end foreach
      $html .= '&lt;/ul&gt;'."\n";
      return $html;
  }// printAssetMap()
  </code></pre>
  
  <p>XML I am using, that has nested nodes:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;assets&gt;
    &lt;asset&gt;
      &lt;asset_name&gt;Home&lt;/asset_name&gt;
      &lt;asset_url&gt;/home&lt;/asset_url&gt;
      &lt;asset_assetid&gt;1&lt;/asset_assetid&gt;
    &lt;/asset&gt;
    &lt;asset&gt;
      &lt;asset_name&gt;Projects&lt;/asset_name&gt;
      &lt;asset_url&gt;/projects&lt;/asset_url&gt;
      &lt;asset_assetid&gt;2&lt;/asset_assetid&gt;
      &lt;asset&gt;
        &lt;asset_name&gt;Portfolio&lt;/asset_name&gt;
        &lt;asset_url&gt;/projects/portfolio&lt;/asset_url&gt;
        &lt;asset_assetid&gt;3&lt;/asset_assetid&gt;
      &lt;/asset&gt;
      &lt;asset&gt;
        &lt;asset_name&gt;Current Jobs&lt;/asset_name&gt;
        &lt;asset_url&gt;/projects/current-jobs&lt;/asset_url&gt;
        &lt;asset_assetid&gt;4&lt;/asset_assetid&gt;
      &lt;/asset&gt;
    &lt;/asset&gt;
  &lt;/assets&gt;
  </code></pre>
  
  <p>Now, I am starting to add child nodes of the nodes that I am currently returning.  Is there a way to loop through ALL levels of child nodes in an xml file, even if I don't know how many levels there are, and add those to my list?</p>