title: Best way to query XDocument with LINQ?
body: <p>I have an XML document that contains a series of item nodes that look like this:</p>
  
  <pre><code>&lt;data&gt;
      &lt;item&gt;
          &lt;label&gt;XYZ&lt;/label&gt;
          &lt;description&gt;lorem ipsum&lt;/description&gt;
          &lt;parameter type="id"&gt;123&lt;/parameter&gt;
          &lt;parameter type="name"&gt;Adam Savage&lt;/parameter&gt;
          &lt;parameter type="zip"&gt;90210&lt;/parameter&gt;
      &lt;/item&gt; 
  &lt;/data&gt;
  </code></pre>
  
  <p>and I want to LINQ it into an anonymous type like this:</p>
  
  <pre><code>var mydata =
      (from root in document.Root.Elements("item")
      select new {
         label = (string)root.Element("label"),
         description = (string)root.Element("description"),
         id = ...,
         name = ...,
         zip = ...
       });
  </code></pre>
  
  <p>What's the best way to pull each parameter type according to the value of its 'type' attribute? Since there are many parameter elements you wind up with <code>root.Elements("parameter")</code> which is a collection. The best way I can think to do it is like this by method below but I feel like there must be a better way?</p>
  
  <pre><code>(from c in root.Descendants("parameter") where (string)c.Attribute("type") == "id"
  select c.Value).SingleOrDefault()
  </code></pre>