title: SimpleXML: Add XML attribute values to an array
body: <p>I want to create an array from the <code>id</code> attributes of the element <code>&lt;b&gt;</code>, however the below code returns all XML. </p>
  
  <p><strong>PHP file:</strong></p>
  
  <pre><code>$xmlfile=simplexml_load_file("test.xml");
  $test=$xmlfile-&gt;xpath("/a//b[@id]");
  </code></pre>
  
  <p><strong>XML file(fixed):</strong>    </p>
  
  <pre><code>&lt;a&gt;
    &lt;b id="1"&gt;&lt;/b&gt;
    &lt;b id="2"&gt;&lt;/b&gt;
    &lt;b id="3"&gt;&lt;/b&gt;
    &lt;b id="4"&gt;&lt;/b&gt;
    &lt;b id="5"&gt;&lt;/b&gt;
  &lt;/a&gt;
  </code></pre>