title: reading value of node that has a specific attribute with Xdocument
body: <p>Im trying to write a List of 'Documents' from an XML string, but i was wondering what is the best way to get the value of a node of certain attribute.</p>
  
  <p>More specifically in the sample I would like to set the value of aDocument.Source to the text "The Source" of the "field" node that has the "Source" value for the "name" attribute.</p>
  
  <p>Sample XML:</p>
  
  <pre><code>&lt;doc&gt;
        &lt;docitem&gt;3&lt;/docitem&gt;
        &lt;docid&gt;129793&lt;/docid&gt;
        &lt;doctitle&gt;Some Title&lt;/doctitle&gt;
        &lt;docdate&gt;2009-07-03&lt;/docdate&gt;
        &lt;metadata&gt;
          &lt;field name="Date"&gt;2009-07-03 14:45:00&lt;/field&gt;
          &lt;field name="SourceArea"&gt;The Source Area&lt;/field&gt;
          &lt;field name="Source"&gt;The Source&lt;/field&gt;
          &lt;field name="Organisation"&gt;Some Organisation&lt;/field&gt;
        &lt;/metadata&gt;
        &lt;summary&gt;
          &lt;summarytext&gt;Some Summary&lt;/summarytext&gt;
        &lt;/summary&gt;
      &lt;/doc&gt;
  </code></pre>
  
  <p>Sample Code</p>
  
  <pre><code>  protected override List&lt;Document&gt; GetDocuments(string xmlString)
          {
              //Parse the string
              XDocument xDocument = XDocument.Parse(xmlString);
  
              //Create a List of Document objects, from the doc xml element.
              List&lt;Document&gt; documents = (from doc in xDocument.Descendants("doc")
                                          select new Document
                                          {
                                              DocId = Convert.ToInt32(doc.Element("docid").Value),
                                              DocTitle = doc.Element("doctitle").Value,
                                              DocDateTime = DateTime.Parse(doc.Element("docdate").Value),
                                              DocSummary = doc.Element("summary").Value,
                                              DocBody = "",
                                              DocUrl = doc.Element("docid").Value,
                                              Source = "" //CODE NEEDED
                                          }
                                          ).ToList&lt;Document&gt;();
  
  
  
              return documents;
  
          }
  </code></pre>