title: Select Xml Node using Linq to XML
body: <p>my Xml file :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ArrayOfCustomer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;Customer&gt;
          &lt;CustomerId&gt;1f323c97-2015-4a3d-9956-a93115c272ea&lt;/CustomerId&gt;
          &lt;FirstName&gt;Aria&lt;/FirstName&gt;
          &lt;LastName&gt;Stark&lt;/LastName&gt;
          &lt;DOB&gt;1999-01-01T00:00:00&lt;/DOB&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;CustomerId&gt;c9c326c2-1e27-440b-9b25-c79b1d9c80ed&lt;/CustomerId&gt;
          &lt;FirstName&gt;John&lt;/FirstName&gt;
          &lt;LastName&gt;Snow&lt;/LastName&gt;
          &lt;DOB&gt;1983-01-01T00:00:00&lt;/DOB&gt;
      &lt;/Customer&gt;
  &lt;/ArrayOfCustomer&gt;  
  </code></pre>
  
  <p>my attempt :</p>
  
  <pre><code>XElement toEdit = 
      (XElement)doc.Descendants("ArrayOfCustomer")
                   .Descendants("Customer")
                   .Where(x =&gt; Guid.Parse((x.Descendants("CustomerId") as XElement).Value) == customer.CustomerId)
                   .First&lt;XElement&gt;();
  </code></pre>
  
  <p>this throws the following exception :</p>
  
  <pre><code> Object reference not set to an instance of an object.
  </code></pre>
  
  <p>1) isn't <code>x</code> an <code>XElement</code>?</p>
  
  <p>2) is this a proper where lambda for selecting an Xml node? </p>
  
  <p>3) and of course how would you find this node according to <code>CustomerId</code>?</p>