title: LINQ to XML: reading XML in C#
body: <p>I am trying to read an XML file using LINQ. I have had no problem reading and parsing simple XML files but this one has me stumped.
  Here is a portion of the file: The file is properly formed and valid.</p>
  
  <pre><code>&lt;Activities&gt;
      &lt;Activity Sport="Other"&gt;
        &lt;Id&gt;2009-12-17T19:53:14Z&lt;/Id&gt;
        &lt;Lap StartTime="2009-12-17T19:53:14Z"&gt;
          &lt;TotalTimeSeconds&gt;820.5400000&lt;/TotalTimeSeconds&gt;
          &lt;DistanceMeters&gt;1510.3433838&lt;/DistanceMeters&gt;
          &lt;MaximumSpeed&gt;2.6089859&lt;/MaximumSpeed&gt;
          &lt;Calories&gt;104&lt;/Calories&gt;
          &lt;AverageHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t"&gt;
            &lt;Value&gt;128&lt;/Value&gt;
          &lt;/AverageHeartRateBpm&gt;
          &lt;MaximumHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t"&gt;
            &lt;Value&gt;139&lt;/Value&gt;
          &lt;/MaximumHeartRateBpm&gt;
          &lt;Intensity&gt;Active&lt;/Intensity&gt;
          &lt;TriggerMethod&gt;Manual&lt;/TriggerMethod&gt;
  </code></pre>
  
  <p>...
  and here is my code</p>
  
  <pre><code>XDocument document = XDocument.Load(myfileXml);
  
  var query = from gtc in document.Descendants("Activities").Elements("Lap")
              select new
              {
                  Id = gtc.Parent.Element("Id").Value,
                  StartTime = gtc.Attribute("StartTime").Value,
                  TotalSeconds = gtc.Element("TotalTimeSeconds").Value,
                  DistanceMeters = gtc.Element("DistanceMeters").Value,
                  MaximumSpeed = gtc.Element("MaximumSpeed").Value,
                  Calories = gtc.Element("Calories").Value,
                  Intensity = gtc.Element("Intensity").Value,
                  TriggerMethod = gtc.Element("TriggerMethod").Value
              };
  
  dataGridView1.DataSource = query.ToList();
  </code></pre>
  
  <p>When I run this, I see the Headers in the DataGridView, but no data. Can someone please tell me where I am going wrong? Also in the solution can someone tell me how to read the value for the heart rates? Thank you!</p>