title: Parsing XML into classes using LINQ in C#
body: <p>I'm having a lot of trouble parsing an XML document into my custom classes. I've tried to read what I can find on the web and on here, but I'm still not getting anywhere. I'm working on a real estate app, and am trying to model a basic property where you have:</p>
  
  <ul>
  <li>1 property</li>
  <li>1 property can have multiple buildings</li>
  <li>Each building can have multiple tenants.</li>
  </ul>
  
  <p>I decided to try to store the data in an xml document, and I made an example as     follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Property&gt;
      &lt;Name&gt;Grove Center&lt;/Name&gt;
      &lt;Building&gt;
          &lt;Name&gt;Building1&lt;/Name&gt;
          &lt;Tenant&gt;
              &lt;Name&gt;Tenant1&lt;/Name&gt;
              &lt;SquareFeet&gt;2300&lt;/SquareFeet&gt;
              &lt;Rent&gt;34000&lt;/Rent&gt;
          &lt;/Tenant&gt;
          &lt;Tenant&gt;
              &lt;Name&gt;Tenant2&lt;/Name&gt;
              &lt;SquareFeet&gt;3100&lt;/SquareFeet&gt;
              &lt;Rent&gt;42000&lt;/Rent&gt;
          &lt;/Tenant&gt;
          &lt;Tenant&gt;
              &lt;Name&gt;Tenant3&lt;/Name&gt;
              &lt;SquareFeet&gt;1700&lt;/SquareFeet&gt;
              &lt;Rent&gt;29000&lt;/Rent&gt;
          &lt;/Tenant&gt;
      &lt;/Building&gt;
      &lt;Building&gt;
          &lt;Name&gt;Building2&lt;/Name&gt;
          &lt;Tenant&gt;
              &lt;Name&gt;Tenant1&lt;/Name&gt;
              &lt;SquareFeet&gt;6150&lt;/SquareFeet&gt;
              &lt;Rent&gt;80000&lt;/Rent&gt;
          &lt;/Tenant&gt;
          &lt;Tenant&gt;
              &lt;Name&gt;Tenant2&lt;/Name&gt;
              &lt;SquareFeet&gt;4763&lt;/SquareFeet&gt;
              &lt;Rent&gt;60000&lt;/Rent&gt;
          &lt;/Tenant&gt;
      &lt;/Building&gt;
  &lt;/Property&gt;
  </code></pre>
  
  <p>Actually my first question is if this format is even correct.. I saw some xml examples where they added an extra tag such as <code>&lt;buildings&gt;</code> before they started listing out the individual <code>&lt;Building&gt;</code> tags for each building. Is that necessary? The W3C examples I saw didn't do it that way.. but this post on stackexchange was pretty close to what im doing: <a href="https://stackoverflow.com/questions/13904414/parsing-xml-with-linq-with-multiple-descendants?rq=1">Parsing XML with Linq with multiple descendants</a></p>
  
  <p>Here is the code for my classes in C#:</p>
  
  <pre><code>public class Property
  {
      public string Name { get; set; }
      public List&lt;Building&gt; Buildings = new List&lt;Building&gt;();
  }
  
  public class Building
  {
      public string Name { get; set; }
      public List&lt;Tenant&gt; Tenants = new List&lt;Tenant&gt;();
  }
  
  public class Tenant
  {
      public string Name { get; set; }
      public int SF { get; set; }
      public decimal Rent { get; set; }
  }
  </code></pre>
  
  <p>I'm not sure if using the new keyword on my lists right in the class definition is good practice.. but I was getting errors trying to add a building or tenant to the list later on in my program so I didn't know what else to do. Right now I'm not much further in my main code than:</p>
  
  <pre><code>Property p = new Property();
  XDocument doc = XDocument.Load(@"C:\Users\SampleUser\Desktop\sample-property.xml");
  </code></pre>
  
  <p>Any help is appreciated, thanks</p>