title: How do I get the value of a descendant element?
body: <p>I have an XML file containing a series of elements like the following:</p>
  
  <pre><code>&lt;trkpt lat="42.403128" lon="-71.084654"&gt;
      &lt;ele&gt;12.153809&lt;/ele&gt;
      &lt;time&gt;2002-03-11T20:49:26Z&lt;/time&gt;
      &lt;sym&gt;Waypoint&lt;/sym&gt;
  &lt;/trkpt&gt;
  </code></pre>
  
  <p>I'm using the following code to grab the <code>lat</code> and <code>lon</code> attributes and add them to a list:</p>
  
  <pre><code>XDocument doc = XDocument.Load(filename);
  
  XElement trkseg = doc.Descendants().Where(x =&gt; x.Name.LocalName == "trkseg").FirstOrDefault();
  XNamespace ns = trkseg.Name.Namespace;
  
  var l_l = trkseg.Elements(ns + "trkpt").Select(x =&gt; new
  {
      lat = x.Attribute("lat").Value,
      lon = x.Attribute("lon").Value
  }).ToList();
  </code></pre>
  
  <p>The above code works as expected. I get a list of strings containing the <code>lat</code> and <code>lon</code> values. We're good so far.</p>
  
  <p>The problem enters when I try to get the value of the <code>&lt;time&gt;</code> element. I've tried several different variations of the following, to no avail:</p>
  
  <pre><code>lat = x.Attribute("lat").Value,
  lon = x.Attribute("lon").Value,
  time = x.Descendants("time").Elements().FirstOrDefault().Value
  </code></pre>
  
  <p>All my attempts resulted in <code>time</code> being <code>null</code>. How do I get the value of the <code>&lt;time&gt;</code> element?</p>