title: C# XML Linq Parsing
body: <p>I'm using VS2010 C#. I have an XML file being read in via XDocument. I need to load the XML data into a class or a var and then be able to access that data to print out to textboxes in a windows form.</p>
  
  <p>I have tried a few things. XDocument.Parse is getting the XML, because I can print it out to a text box and it is all there &amp; correct. From there, however, the data does not seem to be reading into the class or var. (count of 0, elements are null, etc). </p>
  
  <p>I was following this tutorial, but it is quite old now: <a href="http://tech.pro/tutorial/743/introduction-to-linq-simple-xml-parsing" rel="nofollow">http://tech.pro/tutorial/743/introduction-to-linq-simple-xml-parsing</a></p>
  
  <p>Can anyone point me to how 1) I can load the data into a list and 2) access the sub-elements to print out to a text box?</p>
  
  <p>The code:</p>
  
  <pre><code>XDocument xmlResponse = XDocument.Parse( e.Result );
  
  var hds =
   (from hdi in xmlResponse.Descendants("HDInfo")
    select new HDInfo
    {
     freeSpace = (long)hdi.Element("freeSpace"),
     percentFree = (float)hdi.Element("percentFree"),
     volume = (String)hdi.Element("volume"),
    });
  </code></pre>
  
  <p>The XML:</p>
  
  <pre><code>&lt;ArrayOfHDInfo xmlns="http://schemas.datacontract.org/2004/07/project" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
   &lt;HDInfo&gt;
    &lt;freeSpace&gt;187783532544&lt;/freeSpace&gt;
    &lt;percentFree&gt;75.1457443&lt;/percentFree&gt;
    &lt;volume&gt;C:\&lt;/volume&gt;
   &lt;/HDInfo&gt;
   &lt;HDInfo&gt;
    &lt;freeSpace&gt;583875145728&lt;/freeSpace&gt;
    &lt;percentFree&gt;77.83411&lt;/percentFree&gt;
    &lt;volume&gt;D:\&lt;/volume&gt;
   &lt;/HDInfo&gt;
  &lt;/ArrayOfHDInfo&gt;
  </code></pre>