title: Parse XML with Child Nodes
body: <p>I have an XML file which returns a list of products with colors and inventory for each color. What is the best method to loop through this data only returning inventory by color for a specific product i.e. PL-0223?</p>
  
  <p>Here is the data.</p>
  
  <pre><code>&lt;Part fpartno="0019"&gt;
      &lt;Color colorname="Nickel"&gt; 
          &lt;ValueAmt&gt;
              &lt;Values Qty= "12101" Date ="ATP" Type= "Avail"/&gt;
              &lt;Values Qty= "12101" Date= "Total" Type="Total"/&gt; 
          &lt;/ValueAmt&gt;
      &lt;/Color&gt;
  &lt;/Part&gt;
  &lt;Part fpartno="0223"&gt;
      &lt;Color colorname="White"&gt; 
          &lt;ValueAmt&gt;
              &lt;Values Qty= "0" Date ="ATP" Type= "Avail"/&gt;
              &lt;Values Qty= "0" Date= "Total" Type="Total"/&gt; 
          &lt;/ValueAmt&gt;
      &lt;/Color&gt;
      &lt;Color colorname="Yellow"&gt; 
          &lt;ValueAmt&gt;
              &lt;Values Qty= "0" Date ="ATP" Type= "Avail"/&gt;
              &lt;Values Qty= "0" Date= "Total" Type="Total"/&gt; 
          &lt;/ValueAmt&gt;
      &lt;/Color&gt;
  &lt;/Part&gt;
  </code></pre>
  
  <p>I've seen examples using both Linq to SQL and XmlReader but I have not found a good solution to loop through SubTree's/Child Nodes.</p>
  
  <p>Examples of what I've tried.</p>
  
  <p>XmlReader Method.  I can't seem to figure out how to get the sub elements.</p>
  
  <pre><code>using(XmlReader r = XmlReader.Create(URLString))
  {
      while(r.Read())
      {
          if((r.NodeType == XmlNodeType.Element) &amp;&amp; (r.Name == "Part"))
          {
              if(r.HasAttributes)
              {                    
                  if(r.GetAttribute("fpartno") == "0019")
                  {
                      using (XmlReader cr = r.ReadSubtree())
                      {
                          Console.WriteLine(cr.Name)
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I've also tried XDoc</p>
  
  <pre><code>XDocument xdoc = XDocument.Load(URLString);
  foreach (XElement element in xdoc.Descendants("Values"))
  {
      Console.WriteLine(element);
  } 
  </code></pre>
  
  <p>But can't seem to figure out how to only get colors for "0019".</p>