title: Linq to XML - Find an element
body: <p>I am sure that this is basic and probably was asked before, but I am only starting using Linq to XML.</p>
  
  <p>I have a simple XML that i need to read and write to.</p>
  
  <pre><code>&lt;Documents&gt;
  ...
      &lt;Document&gt;
        &lt;GUID&gt;09a1f55f-c248-44cd-9460-c0aab7c017c9-0&lt;/GUID&gt;
        &lt;ArchiveTime&gt;2012-05-15T14:27:58.5270023+02:00&lt;/ArchiveTime&gt;
        &lt;ArchiveTimeUtc&gt;2012-05-15T12:27:58.5270023Z&lt;/ArchiveTimeUtc&gt;
        &lt;IndexDatas&gt;
          &lt;IndexData&gt;
            &lt;Name&gt;Name1&lt;/Name&gt;
            &lt;Value&gt;Some value&lt;/Value&gt;
            &lt;DataType&gt;1&lt;/DataType&gt;
            &lt;CreationTime&gt;2012-05-15T14:27:39.6427753+02:00&lt;/CreationTime&gt;
            &lt;CreationTimeUtc&gt;2012-05-15T12:27:39.6427753Z&lt;/CreationTimeUtc&gt;
          &lt;/IndexData&gt;
          &lt;IndexData&gt;
            &lt;Name&gt;Name2&lt;/Name&gt;
            &lt;Value&gt;Some value&lt;/Value&gt;
            &lt;DataType&gt;3&lt;/DataType&gt;
            &lt;CreationTime&gt;2012-05-15T14:27:39.6427753+02:00&lt;/CreationTime&gt;
            &lt;CreationTimeUtc&gt;2012-05-15T12:27:39.6427753Z&lt;/CreationTimeUtc&gt;
          &lt;/IndexData&gt;
     ...
   &lt;/IndexDatas&gt;
  &lt;/Document&gt;
  ...
  &lt;/Documents&gt;
  </code></pre>
  
  <p>I have a "Documents" node that contains bunch of "Document" nodes.</p>
  
  <p>I have GUID of the document and a "IndexData" name. 
  I need to find the document by GUID and check if it has "IndexData" with some name.
  If it does not have it i need to add it.</p>
  
  <p>Any help would be apreciated, as i have problem with reading and searching trough elements.</p>
  
  <p>Currently I am trying to use (in C#):</p>
  
  <pre><code>IEnumerable&lt;XElement&gt; xmlDocuments = from c in XElement
                                          .Load(filePath)
                                          .Elements("Documents") 
                                           select c;
  
  // fetch document
   XElement documentElementToEdit = (from c in xmlDocuments where 
                      (string)c.Element("GUID").Value == GUID select c).Single();
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>xmlDocuments.Element("Documents").Elements("Document")
  </code></pre>
  
  <p>This returns no result, even tho xmlDocuments.Element("Documents") does. It looks like i cant get Document nodes from Documents node.</p>