title: Deserialize XML into Entitylist using C# from XMLdocument
body: <p>Refer the below XML File with multiple event nodes into parent events tag</p>
  
  <pre><code>&lt;events&gt;
  &lt;event eventid="ahjy67kl" sessionid="1"&gt;
  &lt;eventtitle&gt;
  &lt;![CDATA[ phoneEventchad_1 ]]&gt;
  &lt;/eventtitle&gt;
  &lt;eventabstract/&gt;
  &lt;timezone&gt;IND&lt;/timezone&gt;
  &lt;eventtimedate&gt;Wed, 24 Jun 2015 06:00 PDT&lt;/eventtimedate&gt;
  &lt;archivestartdate&gt;Wed, 24 Jun 2015 09:30 PDT&lt;/archivestartdate&gt;
  &lt;archiveenddate&gt;Thu, 23 Jun 2016 09:30 PDT&lt;/archiveenddate&gt;
  &lt;length&gt;195&lt;/length&gt;
  &lt;sponsor/&gt;
  &lt;keywords/&gt;
  &lt;location/&gt;
  &lt;eventprofile&gt;
  &lt;![CDATA[ Stonehenge Profile (918) ]]&gt;
  &lt;/eventprofile&gt;
  &lt;streamtype&gt;
  &lt;![CDATA[ whitepaper ]]&gt;
  &lt;/streamtype&gt;
  &lt;categories/&gt;
  &lt;eventstdfield1&gt;
  &lt;value/&gt;
  &lt;/eventstdfield1&gt;
  &lt;eventstdfield2/&gt;
  &lt;eventstdfield3/&gt;
  &lt;eventstdfield4/&gt;
  &lt;eventstdfield5/&gt;
  &lt;audiencekeylock&gt;
  &lt;![CDATA[ 770D14C9CC784E9D9D312563B093E9A5 ]]&gt;
  &lt;/audiencekey&gt;
  &lt;urls&gt;
  &lt;audienceurl&gt;
  &lt;![CDATA[
  http://event.on24.com/wcc/r/1012538/770D14C9CC784E9D9D312563B093E9A5&amp;partnerref=rss-scribev3
  ]]&gt;
  &lt;/audienceurl&gt;
  &lt;extaudienceurl/&gt;
  &lt;reporturl&gt;
  &lt;![CDATA[ ##REPORT_URL## ]]&gt;
  &lt;/reporturl&gt;
  &lt;uploadurl&gt;
  &lt;![CDATA[ ##UPLOAD_URL## ]]&gt;
  &lt;/uploadurl&gt;
  &lt;presenterurl&gt;
  &lt;![CDATA[ ##PRESENTER_URL## ]]&gt;
  &lt;/presenterurl&gt;
  &lt;/urls&gt;
  &lt;speakers/&gt;
  &lt;registrationstats&gt;
  &lt;registrantcount&gt;0&lt;/registrantcount&gt;
  &lt;/registrationstats&gt;
  &lt;attendancestats&gt;
  &lt;attendedcount&gt;0&lt;/attendedcount&gt;
  &lt;noshowcount&gt;0&lt;/noshowcount&gt;
  &lt;attendedlivecount&gt;0&lt;/attendedlivecount&gt;
  &lt;attendedarchivecount&gt;0&lt;/attendedarchivecount&gt;
  &lt;/attendancestats&gt;
  &lt;partnerrefstats/&gt;
  &lt;tags/&gt;
  &lt;registrants&gt;&lt;/registrants&gt;
  &lt;attendees&gt;&lt;/attendees&gt;
  &lt;/event&gt;
  &lt;/events&gt;
  </code></pre>
  
  <p>"</p>
  
  <p>Entity Class</p>
  
  <pre><code>public class events
  {
      private Event _event;
  
      [XmlElement(ElementName = "event")] 
      public Event Event
      {
          get
          {
              return this._event;
          }
          set
          {
              this._event = value;
          }
      }
  }
  
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  public class Event
  {
      public string eventid { get; set; }
      public string sessionid { get; set; }
      public string eventTitle { get; set; }      
      public DateTime archivestartdate { get; set; }
      public DateTime archiveenddate { get; set; }
      public string eventabstract { get; set; }
      public DateTime eventtimedate { get; set; }
      public string eventprofile { get; set; }
      public string registrantcount { get; set; }
      public string sponsor { get; set; }
      public string keywords { get; set; }
      public string eventstdfield1 { get; set; }
      public string eventstdfield2 { get; set; }
      public string eventstdfield3 { get; set; }
      public string eventstdfield4 { get; set; }
      public string eventstdfield5 { get; set; }
      public attendancestats attendancestats { get; set; }
      public registrationstats registrationstats { get; set; }
  
      public Event()
      { }
  }
  
  public class attendancestats
  {
      public string attendedcount { get; set; }
      public string noshowcount { get; set; }
      public string attendedlivecount { get; set; }
      public string attendedarchivecount { get; set; }       
  
  }
  public class registrationstats
  {
      public string registrantcount { get; set; } 
  }
  </code></pre>
  
  <p>I used below code to deserlize the menioned XML into above Entity class</p>
  
  <p>pDoc is the object of XMLdocument filled with above xml</p>
  
  <p>System.Xml.Serialization.XmlRootAttribute xRoot = new System.Xml.Serialization.XmlRootAttribute();
              xRoot.ElementName = "events";
              xRoot.IsNullable = true;</p>
  
  <pre><code>        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List&lt;events&gt;),xRoot);
          XDocument Doc = new XDocument();
          Doc = XDocument.Parse(pDoc.OuterXml);
          //System.Xml.XmlReader reader = Doc.CreateReader();
          XmlReader reader = XmlReader.Create(new System.IO.StringReader(Doc.ToString()));
          List&lt;Event&gt; result = (List&lt;Event&gt;)serializer.Deserialize(reader);
          reader.Close();
  </code></pre>
  
  <p>In above code reader object is getting null due to which result object of List is throwing exception.</p>
  
  <p>I want the List of Events.</p>
  
  <p>Please help me to achieve list of events. let me know if need to provide further details.</p>