title: Is it possible to get populate class object from xml?
body: <p>I have an xml file like this:</p>
  
  <p></p>
  
  <pre><code>  &lt;CommissionTypes&gt;
      &lt;Type&gt;CPA&lt;/Type&gt;
      &lt;Lender&gt;
        &lt;Seq&gt;001&lt;/Seq&gt;
        &lt;PostUrl&gt;http://www.mysite.com&lt;/PostUrl&gt;
      &lt;/Lender&gt;
    &lt;/CommissionTypes&gt;
  &lt;/Lenders&gt;
  </code></pre>
  
  <p>Having got the data like this:</p>
  
  <pre><code>var config = XDocument.Load(xml);
  </code></pre>
  
  <p>I need to map it to a class collection, the class is structured like this:</p>
  
  <pre><code>public class Lender
  {
      public string Type { get; set; }
      public int Seq { get; set; }
      public string PostUrl { get; set; }
  
      public void Lender(string type, int seq, string postUrl)
      {
          Type = type;
          Seq = seq;
          PostUrl = postUrl;
      }
  }
  </code></pre>
  
  <p>I've been trying to do this for some time using linq, but without success as yet. What i want to do is retrieve all lenders with in the type "CPA" or any other type.</p>
  
  <p>Any advice?</p>
  
  <p>// <strong>* UPDATE *</strong> //</p>
  
  <p>The update below is where I'm currently at. Its not working, getting a 'object reference not set to an instance' error wgere arrow is.</p>
  
  <pre><code>&lt;CommissionTypes&gt;
    &lt;Type type="CPA"&gt;
      &lt;Lender&gt;
        &lt;Seq&gt;001&lt;/Seq&gt;
        &lt;PostUrl&gt;http://www.mysite.com&lt;/PostUrl&gt;
      &lt;/Lender&gt;
    &lt;/Type&gt;
  &lt;/CommissionTypes&gt;
  
      public static List&lt;Lender&gt; GetLenders(string xml)
      {
          var myXml = XDocument.Load(xml);
  
          var lenders = new List&lt;Lender&gt;();
  
          lenders = (from type in myXml.Descendants("Type")
                 where type.Attribute("type").Value == "CPA"
          ===&gt;   select new Lender(
                  "CPA",
                  type.Element("Seq").Value.ConvertTo&lt;int&gt;(),
                  type.Element("PostUrl").Value)).ToList();
  
          return lenders;
      }
  </code></pre>