title: Using XMLReader to read large XML documents to parse the information into a class
body: <p>I have been using XDocument combined with LINQ to XML to load in xml files and populate my class. </p>
  
  <p>But now I am tasked with making sure my program can handle all sizes of XML documents which means i need to use XML Reader and at this time being i cant get my head around manipulating the XMLReader to populate my class.</p>
  
  <p>currently i have the below class to populate:</p>
  
  <pre><code> public class DataRecord
    {
      private List&lt;Fields&gt; field = new List&lt;Fields&gt;();
  
      public string ID { get; set; }
      public string TotalLength { get; set; }
  
      public List&lt;Fields&gt; MyProperty
      {
        get { return field; }
        set { field = value; }
      }
  
    }
  
    internal class Fields
    {
      public string name { get; set; }
      public string startByte { get; set; }
      public string length { get; set; }
    }
  
  }
  </code></pre>
  
  <p>I have been trying to switch statements to enforce the xmlreader to provide the data from me to populate the class. For example:</p>
  
  <pre><code>using (XmlReader reader = XmlReader.Create(filename))
    {
      while (reader.Read())
      {
        switch (reader.NodeType)
        {
          case XmlNodeType.Element:
            switch (reader.Name)
            {
              case "DataRecord":
                var dataaa = new dataclass.DataRecord();
                break;
            }
           break;
        }
      }
    }
  </code></pre>
  
  <p>But as i said this is an example, I have searched for ages to try and find an answer but I am getting confused. Hopefully someone can help we my problem.</p>