title: How can I select an xml element by attribute without iterating using PHP?
body: <p>I have this XML from <a href="http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" rel="nofollow">http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml</a></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"&gt;
      &lt;gesmes:subject&gt;Reference rates&lt;/gesmes:subject&gt;
      &lt;gesmes:Sender&gt;
          &lt;gesmes:name&gt;European Central Bank&lt;/gesmes:name&gt;
      &lt;/gesmes:Sender&gt;
      &lt;Cube&gt;
          &lt;Cube time='2013-08-23'&gt;
              &lt;Cube currency='USD' rate='1.3355'/&gt;
              &lt;Cube currency='GBP' rate='0.85910'/&gt;
              &lt;Cube currency='HUF' rate='298.98'/&gt;
          &lt;/Cube&gt;
      &lt;/Cube&gt;
  &lt;/gesmes:Envelope&gt;
  </code></pre>
  
  <p>(I removed some values for demonstrational purposes)</p>
  
  <p>I want to get the conversion rate, for lets say, GBP using PHP.</p>
  
  <p>HI can load it using simplexml like this:</p>
  
  <pre><code>$XML=simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
  
      foreach($XML-&gt;Cube-&gt;Cube-&gt;Cube as $rate){
  ...
  </code></pre>
  
  <p>But I would like to get the value without iterating, and i really dont want to use regex...</p>
  
  <p>I tried something like this but it didnt work:</p>
  
  <pre><code>$sxe=simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
  
  $sxe-&gt;registerXPathNamespace('c', 'http://www.gesmes.org/xml/2002-08-01');
  $result = $sxe-&gt;xpath('//c:Cube[@currency="USD"]');
  </code></pre>