title: Obtain child node based on attribute of parent node
body: <p>I have a CrystalReport report in XML (sorry for the verboseness, I cut out most sample data)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;FormattedReport xmlns = 'urn:crystal-reports:schemas' xmlns:xsi = 'http://www.w3.org/2000/10/XMLSchema-instance'&gt;
  &lt;FormattedAreaPair Level="0" Type="Report"&gt;
  &lt;FormattedAreaPair Level="1" Type="Details"&gt;
  &lt;FormattedArea Type="Details"&gt;
  &lt;FormattedSections&gt;
  &lt;FormattedSection SectionNumber="0"&gt;
  &lt;FormattedReportObjects&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{AIRCRAFT.Tail Number}"&gt;&lt;ObjectName&gt;Field2&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;C-FBCS&lt;/FormattedValue&gt;
  &lt;Value&gt;C-FBCS&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{AIRCRAFT.Type ID}"&gt;&lt;ObjectName&gt;Field8&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;DHC8&lt;/FormattedValue&gt;
  &lt;Value&gt;DHC8&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:unsignedLong" FieldName="{TRIP LEGS.Trip Number}"&gt;&lt;ObjectName&gt;Field9&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;68344&lt;/FormattedValue&gt;
  &lt;Value&gt;68344.00&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;/FormattedReportObjects&gt;
  &lt;/FormattedSection&gt;
  &lt;/FormattedSections&gt;
  &lt;/FormattedArea&gt;
  &lt;/FormattedAreaPair&gt;
  &lt;FormattedAreaPair Level="1" Type="Details"&gt;
  &lt;FormattedArea Type="Details"&gt;
  &lt;FormattedSections&gt;
  &lt;FormattedSection SectionNumber="0"&gt;
  &lt;FormattedReportObjects&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{AIRCRAFT.Tail Number}"&gt;&lt;ObjectName&gt;Field2&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;C-FBCS&lt;/FormattedValue&gt;
  &lt;Value&gt;C-FBCS&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{AIRCRAFT.Type ID}"&gt;&lt;ObjectName&gt;Field8&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;DHC8&lt;/FormattedValue&gt;
  &lt;Value&gt;DHC8&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;FormattedReportObject xsi:type="CTFormattedField" Type="xsd:unsignedLong" FieldName="{TRIP LEGS.Trip Number}"&gt;&lt;ObjectName&gt;Field9&lt;/ObjectName&gt;
  &lt;FormattedValue&gt;68344&lt;/FormattedValue&gt;
  &lt;Value&gt;68344.00&lt;/Value&gt;
  &lt;/FormattedReportObject&gt;
  &lt;/FormattedReportObjects&gt;
  &lt;/FormattedSection&gt;
  &lt;/FormattedSections&gt;
  &lt;/FormattedArea&gt;
  &lt;/FormattedAreaPair&gt;
  ...
  &lt;/FormattedAreaPair&gt;
  &lt;/FormattedReport&gt;
  </code></pre>
  
  <p>I am attempting to use a LINQ to XML query to extract the 
  <em>Value</em> node based on the parent node's <em>FieldName</em> attribute and place those into an object. There is no unique attribute for Value or the parents of FormattedReportObject nodes.  So far here is my code to do so</p>
  
  <pre><code>from fs in xDoc.Descendants("FormattedSection")
  select new FlightSchedule
  {
    AircraftType = from fos in fs.Descendants("FormattedReportObjects")
                   from fo in fs.Descendants("FormattedReportObject")
                   where fo.Attribute("FieldName").Value.Equals("{AIRCRAFT.Type ID}")
                   from e in fo.Element("Value")
                   select e.Value),
    ....
  };
  </code></pre>
  
  <p>I keep getting errors:</p>
  
  <blockquote>
    <p>An expression of type 'System.Xml.Linq.XElement' is not allowed in a subsequent from clause in a query expression with source type 'System.Collections.Generic.IEnumerable'. Type inference failed in the call to 'SelectMany')</p>
  </blockquote>
  
  <p>or if I don't get an error I end up retrieving nothing.  Any suggestions would be greatly appreciated on improving my query.</p>