title: Deserialize only specific item from XML and add to list
body: <p>I've got an XML file with multiple items, and I want to deserialize only a single specific one at a time, rather than all of them, and add it to a list.</p>
  
  <p>Using the example from <a href="http://www.janholinka.net/Blog/Article/11" rel="nofollow">this site</a>, how do I deserialize only the <code>Product</code> where <code>Id=2</code> and add it to <code>productList</code>?</p>
  
  <p>The Class:</p>
  
  <pre><code>public class Product
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>void foo()
  {
  string xmlString = "&lt;Products&gt;&lt;Product&gt;&lt;Id&gt;1&lt;/Id&gt;&lt;Name&gt;My XML product&lt;/Name&gt;&lt;/Product&gt;&lt;Product&gt;&lt;Id&gt;2&lt;/Id&gt;&lt;Name&gt;My second product&lt;/Name&gt;&lt;/Product&gt;&lt;/Products&gt;";
  
  XmlSerializer serializer = new XmlSerializer(typeof(List&lt;Product&gt;), new XmlRootAttribute("Products"));
  
  StringReader stringReader = new StringReader(xmlString);
  
  List&lt;Product&gt; productList = (List&lt;Product&gt;)serializer.Deserialize(stringReader);
  }
  </code></pre>