title: Extract XML attribute values as variables in C#
body: <p>Given the following 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>), how can I extract the date, USD rate, and GBP rate as three separate string variables?</p>
  
  <pre><code>&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="2015-11-05"&gt;
  &lt;Cube currency="USD" rate="1.0883"/&gt;
  &lt;Cube currency="JPY" rate="132.65"/&gt;
  &lt;Cube currency="BGN" rate="1.9558"/&gt;
  &lt;Cube currency="CZK" rate="27.044"/&gt;
  &lt;Cube currency="DKK" rate="7.4592"/&gt;
  &lt;Cube currency="GBP" rate="0.71260"/&gt;
  &lt;Cube currency="HUF" rate="313.97"/&gt;
  &lt;Cube currency="PLN" rate="4.2392"/&gt;
  &lt;Cube currency="RON" rate="4.4486"/&gt;
  &lt;Cube currency="SEK" rate="9.3916"/&gt;
  &lt;Cube currency="CHF" rate="1.0833"/&gt;
  &lt;Cube currency="NOK" rate="9.3065"/&gt;
  &lt;Cube currency="HRK" rate="7.5545"/&gt;
  &lt;Cube currency="RUB" rate="68.8654"/&gt;
  &lt;Cube currency="TRY" rate="3.1215"/&gt;
  &lt;Cube currency="AUD" rate="1.5233"/&gt;
  &lt;Cube currency="BRL" rate="4.1364"/&gt;
  &lt;Cube currency="CAD" rate="1.4320"/&gt;
  &lt;Cube currency="CNY" rate="6.9065"/&gt;
  &lt;Cube currency="HKD" rate="8.4351"/&gt;
  &lt;Cube currency="IDR" rate="14751.76"/&gt;
  &lt;Cube currency="ILS" rate="4.2333"/&gt;
  &lt;Cube currency="INR" rate="71.7100"/&gt;
  &lt;Cube currency="KRW" rate="1240.66"/&gt;
  &lt;Cube currency="MXN" rate="17.9972"/&gt;
  &lt;Cube currency="MYR" rate="4.6781"/&gt;
  &lt;Cube currency="NZD" rate="1.6450"/&gt;
  &lt;Cube currency="PHP" rate="51.047"/&gt;
  &lt;Cube currency="SGD" rate="1.5310"/&gt;
  &lt;Cube currency="THB" rate="38.702"/&gt;
  &lt;Cube currency="ZAR" rate="15.1123"/&gt;
  &lt;/Cube&gt;
  &lt;/Cube&gt;
  &lt;/gesmes:Envelope&gt;
  </code></pre>
  
  <p>Here is what I have tried so far which is not working:</p>
  
  <pre><code>var xmlString = (new WebClient()).DownloadString("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
  XDocument doc = XDocument.Parse(xmlString);
  var getGBP = from d in doc.Descendants("Cube")
      where d.Element("Cube").Element("Cube").Attribute("currency").Value == "GBP"
      select d.Element("Cube").Element("Cube").Attribute("rate").Value.FirstOrDefault();
  
  var gbpResult = getGBP.ToString();
  </code></pre>