title: Simple LINQ to XML
body: <p>In C#, how can I select values from an XML file using LINQ?</p>
  
  <p>Here is my XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Level1&gt;
  &lt;Level2&gt;
      &lt;Value1&gt;This-is-value-1&lt;/Value1&gt;
      &lt;Value2&gt;This-is-value-2&lt;/Value2&gt;
      &lt;Value3&gt;This-is-value-3&lt;/Value3&gt;
      &lt;Value4&gt;This-is-value-4&lt;/Value4&gt;
  &lt;/Level2&gt;  
  &lt;/Level1&gt;
  </code></pre>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>var doc = XDocument.Load(filename);
  var values = from lv1 in doc.Descendants("level1")
              from lvl2 in lv1.Descendants("Level2")
              select new {
                  Value1 = lv1.Attribute("Value1").Value,
                  Value2 = lv1.Descendants("Value2").Value,
                  Value3 = lv1.Descendants("Value3").Value,
                  Value4 = lv1.Descendants("Value4").Value,
              };
  </code></pre>
  
  <p>I am wanting to retrieve the following values:</p>
  
  <ul>
  <li>Value1 </li>
  <li>Value2</li>
  <li>Value3</li>
  <li>Value4</li>
  </ul>
  
  <p>May I please have some help to get this working?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Sorry, I meant to add that I would like to place the values in local fields.</p>
  
  <p>E.g. Here are the field names:</p>
  
  <pre><code>string Value1;
  string Value2;
  string Value3;
  string Value4;
  </code></pre>
  
  <p>May I have some help to place the values from the LINQ statement into the local fields?</p>