title: SimpleXML, associative arrays, and XPath
body: <p>I have a question about xpath and arrays.  What I was wondering was if it is possible to use xpath on some simpleXML and have it return an associative array of node names and their values. For example, say I have the following XML:</p>
  
  <pre><code>&lt;element1 page="1"&gt;blah&lt;/element1&gt;
  &lt;element2 page="1"&gt;blah blah&lt;/element2&gt;
  &lt;element3 page="2"&gt;blah&lt;/element3&gt;
  &lt;element4 page="3"&gt;blah blah&lt;/element4&gt;
  </code></pre>
  
  <p>Now if I were to go <code>$xml-&gt;xpath('//node()[@page="1"]');</code> then it would return an array like the following:</p>
  
  <pre><code>array( 0 =&gt; 'blah' , 1 =&gt; 'blah blah' );
  </code></pre>
  
  <p>Is it possible to get an array similar to the one below?</p>
  
  <pre><code>array( element1 =&gt; 'blah' , element2 =&gt; 'blah blah' );
  </code></pre>
  
  <p>Thanks for the help!</p>