title: PHP - How do I read all attributes of XML items using simpleXML?
body: <p>I'm making a script, that reads through the passed XML file and displays the source code. I've got it almost done, but the item attributes .. I can't find a way to catch them. Here's the code:</p>
  
  <pre><code>$xml = simplexml_load_file("path/to/file.xml");
  
      showTree($xml-&gt;children(), 0);
  
      function showTree($value, $i) {
  
          if($value == '') {
  
              foreach($value as $name2 =&gt; $value2) {
  
                  echo str_repeat('--', $i)." &lt;$name2&gt; \n";
                      showTree($value2, ($i+1));
                  echo str_repeat('--', $i)." &lt;/$name2&gt; \n";
              }
  
          } else { echo str_repeat('--', $i)." ".trim($value)."\n"; }
  
      } // end: function  
  </code></pre>
  
  <p>As I said, it works fine, but doesn't display the attributes, for example:</p>
  
  <pre><code>&lt;item id=2&gt;Item&lt;/item&gt;
  </code></pre>
  
  <p>returns only the:</p>
  
  <pre><code>&lt;item&gt;Item&lt;/item&gt;
  </code></pre>
  
  <p>Thanks for any responses, Mike.</p>