title: Reading Specific elements using XMLReader and adding values to a generic List
body: <p>I am reading a huge XML file (250 MB) using XMLReader and add only specific elements to a generic List . I am unable to add values to the list correctly.I am getting null values in the List.I'll appreciate your help Below is the class I am using :</p>
  
  <pre><code>public class SomeInfo
      {
         public string Item1 { get; set; }
  
         public string Item2 { get; set; }
  
      }
  </code></pre>
  
  <p>My code to read XML is as below :</p>
  
  <pre><code>using (XmlReader reader = XmlReader.Create(file)
                  )
              {
                  List&lt;SomeInfo&gt; test = new List&lt;SomeInfo&gt;();
  
                  while (reader.Read())
                  {
                      var testObject = new SomeInfo();
                      if (reader.NodeType == XmlNodeType.Element)
                      {
  
                          string name = reader.Name;
                          switch (name)
                          {
                              case "Item1":
                                  reader.Read();
                                  testObject.item1= reader.Value;
                                  break;
                              case "Item2":
                                  reader.Read();
                                  testObject.item2= reader.Value;
                                  break;
                          }
              test.Add(testObject);
                      }
  
                      }
  </code></pre>
  
  <p>Sample XML : This is huge xml file and I only need to read some elements and add to the list .In my code above, I am only reading Item1 and Item2 and do not care about Xitem,Bitem and Citem tags</p>
  
  <pre><code>&lt;mainItem&gt;
  &lt;Item&gt;
        &lt;Xitem&gt;125&lt;/Xitem&gt;
        &lt;Item1&gt;ab41gh80020gh140f6&lt;/Item1&gt;
        &lt;BItem&gt;42ae3de3&lt;/BItem&gt;
        &lt;Item2&gt;7549tt80384&lt;/Item2&gt;
        &lt;Citem&gt;c7dggf66e4&lt;/Citem&gt;
  &lt;/Item&gt;
  &lt;Item&gt;
        &lt;Xitem&gt;865&lt;/Xitem&gt;
        &lt;Item1&gt;ab41gh80020gh140f6&lt;/Item1&gt;
        &lt;BItem&gt;42aejj3de3&lt;/BItem&gt;
        &lt;Item2&gt;7549kljj80384&lt;/Item2&gt;
        &lt;Citem&gt;c7df6kk6e4&lt;/Citem&gt;
  &lt;/Item&gt;
  &lt;Item&gt;
        &lt;Xitem&gt;895&lt;/Xitem&gt;
        &lt;Item1&gt;ab41gjgjgh80020gh140f6&lt;/Item1&gt;
        &lt;BItem&gt;42aehkh3de3&lt;/BItem&gt;
        &lt;Item2&gt;754980384&lt;/Item2&gt;
        &lt;Citem&gt;c7dfjj66e4&lt;/Citem&gt;
  &lt;/Item&gt;
      &lt;/mainItem&gt;
  </code></pre>