title: Creating objects from child elements using LINQ to XML
body: <p>Is there any way to use a LINQ to XML to query an XML document like the one below to create new (anonymous or strongly typed) objects from the child elements of a descendant? </p>
  
  <p>Here is my XML document:</p>
  
  <pre><code>&lt;Root&gt;
   &lt;Rules&gt;
    &lt;Rule Name="Rule_A"&gt;
     &lt;Parameter&gt;
      &lt;Name&gt;Parameter 1&lt;/Parameter&gt;
      &lt;Value&gt;100&lt;/Value&gt;
     &lt;/Parameter&gt;
     &lt;Parameter&gt;
      &lt;Name&gt;Parameter 2&lt;/Parameter&gt;
      &lt;Value&gt;200&lt;/Value&gt;
     &lt;Parameter&gt;
    &lt;/Rule&gt;
    &lt;Rule Name="Rule_B"&gt;
     &lt;Parameter&gt;
      &lt;Name&gt;Parameter 1&lt;/Parameter&gt;
      &lt;Value&gt;600&lt;/Value&gt;
     &lt;/Parameter&gt;
     &lt;Parameter&gt;
      &lt;Name&gt;Parameter 2&lt;/Parameter&gt;
      &lt;Value&gt;300&lt;/Value&gt;
     &lt;Parameter&gt;
    &lt;/Rule&gt;
   &lt;/Rules&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>My LINQ query looks like this:</p>
  
  <pre><code>Dim RuleName as String = "Rule_A"
  Dim parms() = (From p In pXDoc.Descendants("Rule") _
                 Where p.Attributes("Name").Any And p.Attribute("Name").Value.Equals(RuleName) _
                 Select New DataParameter With { _
                     '' Here is where I would like to pull the values of the Parameter
                     '' elements underneath "Rule_A" and construct an object like below
                     .Name = LINQ magic to get the value of &lt;Name&gt;
                     .Value = LINQ magic to get the value of &lt;Value&gt;
                 }).ToArray
  </code></pre>
  
  <p>After running that query, my <code>Parms()</code> array would have two objects in it representing the Name/Values of <code>"Parameter 1"</code> and <code>"Parameter 2"</code> that fall under <code>"Rule_A"</code>.</p>
  
  <p>The closest I have been able to get is using the <code>p.Element(Parameter).Element(Name).Value</code>, but that won't work as I will only get the first <code>Parameter</code> element. I also tried using <code>Elements()</code>, but was not able to figure out how I would get the value of each. </p>