title: Linq to XML, Parsing string for list of Elements, Printing strings with two descendants each Elem on the list
body: <p>Overall, I'm trying to print a string that is made up of the "title" and "cap:areaDesc" from each entry.  I've gotten to where I can print either the title or other elements, or even a list of elements.  I need them to come out together for their "entry".</p>
  
  <p>I've been through countless posts on stackoverflow, some of which helped to get me this far, but I haven't found anything to address this issue.  I think the biggest problem is my trouble forming good linq queries to the XML.</p>
  
  <p>My logic is to load the xmlstring into either an Xdocument or XElement (not sure which is better), create an IEnumerable list of all elements named "entry", and for each entry, go into its descendants and get the value for both "title" element and cap:areaDesc" elements.  Then concat the strings into a single string.  Finally each of those strings will come together in one long string that lists title and areaDesc for each entry. For testing purposes I'm trying to print the final long string in the console.</p>
  
  <p>EDIT to add: I don't want to print the "title" tag near the start that is not under any "entry" tag; only "title" and "cap:areaDesc" under "entry" tags.</p>
  
  <pre><code>        XDocument root = XDocument.Parse(xmlString);
          XNamespace ns = XNamespace.Get("http://www.w3.org/2005/Atom");
          IEnumerable&lt;XElement&gt; xlist =
              root.Descendants(ns + "entry").Select(elem =&gt; elem.Descendants(ns + "title").Single());
          foreach (XElement el in xlist)
          {
              Console.WriteLine("title: " + el.Value);
          }
  </code></pre>
  
  <p>So that will print the title for each entry, but I can't figure out how to get title and areaDesc together.</p>
  
  <p>I also tried things like:</p>
  
  <pre><code>        XElement xdoc = XElement.Parse(xmlString);
          IEnumerable&lt;XElement&gt; feed = xdoc.Elements();
          Console.WriteLine("Current Alerts:");
          foreach (var entry in feed)
          {
              Console.WriteLine("Alert: {0} has ID: {1}",
                  entry.Element("title").Value,
                  entry.Element("id").Value);
          }
  </code></pre>
  
  <p>but it's not dealing with the namespace, among other issues.</p>
  
  <p>Here is the string (sorry for length, but I didn't want to cut anything that affects how this class will run, and I already cut all the "entry" tags except two).</p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?&gt;
  
  &lt;!--
  This atom/xml feed is an index to active advisories, watches and warnings 
  issued by the National Weather Service.  This index file is not the complete 
  Common Alerting Protocol (CAP) alert message.  To obtain the complete CAP 
  alert, please follow the links for each entry in this index.  Also note the 
  CAP message uses a style sheet to convey the information in a human readable 
  format.  Please view the source of the CAP message to see the complete data 
  set.  Not all information in the CAP message is contained in this index of 
  active alerts.
  --&gt;
  
  
  &lt;feed
  xmlns = 'http://www.w3.org/2005/Atom'
  xmlns:cap = 'urn:oasis:names:tc:emergency:cap:1.1'
  xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
  &gt;
  &lt;!-- http-date = Thu, 19 Sep 2013 10:36:00 GMT --&gt;
  
   &lt;id&gt;http://alerts.weather.gov/cap/la.atom&lt;/id&gt;
  &lt;logo&gt;http://alerts.weather.gov/images/xml_logo.gif&lt;/logo&gt;
  &lt;generator&gt;NWS CAP Server&lt;/generator&gt;
  &lt;updated&gt;2013-09-19T05:36:00-05:00&lt;/updated&gt;
  &lt;author&gt;
  &lt;name&gt;w-nws.webmaster@noaa.gov&lt;/name&gt;
  &lt;/author&gt;
  &lt;title&gt;Current Watches, Warnings and Advisories for Louisiana Issued by the National     Weather Service&lt;/title&gt;
  &lt;link href='http://alerts.weather.gov/cap/la.atom'/&gt;
  
  &lt;entry&gt;
  &lt;id&gt;http://alerts.weather.gov/cap/wwacapget.php?x=LA124F1847F5BC.CoastalFloodAdvisory.124F1855EA00LA.LIXCFWLIX.9647349518939f7318139bd7d878c452&lt;/id&gt;
  &lt;updated&gt;2013-09-19T03:55:00-05:00&lt;/updated&gt;
  &lt;published&gt;2013-09-19T03:55:00-05:00&lt;/published&gt;
  &lt;author&gt;
  &lt;name&gt;w-nws.webmaster@noaa.gov&lt;/name&gt;
  &lt;/author&gt;
  &lt;title&gt;Coastal Flood Advisory issued September 19 at 3:55AM CDT until September 19 at 7:00PM CDT by NWS&lt;/title&gt;
  &lt;link href="http://alerts.weather.gov/cap/wwacapget.php?x=LA124F1847F5BC.CoastalFloodAdvisory.124F1855EA00LA.LIXCFWLIX.9647349518939f7318139bd7d878c452"/&gt;
  &lt;summary&gt;...PERSISTENT EAST WINDS COMBINED WITH TIDES COULD CAUSE MINOR COASTAL FLOODING... .PROLONGED EAST WINDS HAVE RESULTED IN SLIGHT WATER BUILDUP WHICH MAY RESULT IN MINOR COASTAL FLOODING FOR EASTERN FACING SHORELINES THROUGH THIS EVENING. EXPECT TIDES TO BE ONE TO TWO FEET ABOVE NORMAL. IF LOW PRESSURE DEVELOPS OVER THE LOWER GULF OF MEXICO&lt;/summary&gt;
  &lt;cap:event&gt;Coastal Flood Advisory&lt;/cap:event&gt;
  &lt;cap:effective&gt;2013-09-19T03:55:00-05:00&lt;/cap:effective&gt;
  &lt;cap:expires&gt;2013-09-19T19:00:00-05:00&lt;/cap:expires&gt;
  &lt;cap:status&gt;Actual&lt;/cap:status&gt;
  &lt;cap:msgType&gt;Alert&lt;/cap:msgType&gt;
  &lt;cap:category&gt;Met&lt;/cap:category&gt;
  &lt;cap:urgency&gt;Expected&lt;/cap:urgency&gt;
  &lt;cap:severity&gt;Minor&lt;/cap:severity&gt;
  &lt;cap:certainty&gt;Likely&lt;/cap:certainty&gt;
  &lt;cap:areaDesc&gt;LAZ069; Lower Jefferson; Lower Lafourche; Lower St. Bernard; Orleans; Upper St. Bernard&lt;/cap:areaDesc&gt;
  &lt;cap:polygon&gt;&lt;/cap:polygon&gt;
  &lt;cap:geocode&gt;
  &lt;valueName&gt;FIPS6&lt;/valueName&gt;
  &lt;value&gt;022051 022057 022071 022087&lt;/value&gt;
  &lt;valueName&gt;UGC&lt;/valueName&gt;
  &lt;value&gt;LAZ062 LAZ064 LAZ067 LAZ068 LAZ069 LAZ070&lt;/value&gt;
  &lt;/cap:geocode&gt;
  &lt;cap:parameter&gt;
  &lt;valueName&gt;VTEC&lt;/valueName&gt;
  &lt;value&gt;/O.CON.KLIX.CF.Y.0003.000000T0000Z-130920T0000Z/&lt;/value&gt;
  &lt;/cap:parameter&gt;
  &lt;/entry&gt;
  
  &lt;entry&gt;
  &lt;id&gt;http://alerts.weather.gov/cap/wwacapget.php?x=LA124F183A324C.SpecialWeatherStatement.124F18497874LA.JANSPSJAN.39120e8b079d7137b7a148950e61a666&lt;/id&gt;
  &lt;updated&gt;2013-09-18T13:35:00-05:00&lt;/updated&gt;
  &lt;published&gt;2013-09-18T13:35:00-05:00&lt;/published&gt;
  &lt;author&gt;
  &lt;name&gt;w-nws.webmaster@noaa.gov&lt;/name&gt;
  &lt;/author&gt;
  &lt;title&gt;Special Weather Statement issued September 18 at 1:35PM CDT by NWS&lt;/title&gt;
  &lt;link href="http://alerts.weather.gov/cap/wwacapget.php?x=LA124F183A324C.SpecialWeatherStatement.124F18497874LA.JANSPSJAN.39120e8b079d7137b7a148950e61a666"/&gt;
  &lt;summary&gt;...HIGH FIRE DANGER CONDITIONS EXPECTED THROUGH THE END OF THE WEEK... ACCORDING TO AREA FORESTRY COMMISSIONS AND THE US FOREST SERVICE, RECENT DRY CONDITIONS HAVE MADE OUTDOOR BURNING INCREASINGLY HAZARDOUS. CONDITIONS ARE SUCH THAT A SPARK FROM EQUIPMENT, THE HEAT FROM A CATALYTIC CONVERTER, OR ANY HEAT SOURCE COULD START A GRASS&lt;/summary&gt;
  &lt;cap:event&gt;Special Weather Statement&lt;/cap:event&gt;
  &lt;cap:effective&gt;2013-09-18T13:35:00-05:00&lt;/cap:effective&gt;
  &lt;cap:expires&gt;2013-09-19T13:45:00-05:00&lt;/cap:expires&gt;
  &lt;cap:status&gt;Actual&lt;/cap:status&gt;
  &lt;cap:msgType&gt;Alert&lt;/cap:msgType&gt;
  &lt;cap:category&gt;Met&lt;/cap:category&gt;
  &lt;cap:urgency&gt;Expected&lt;/cap:urgency&gt;
  &lt;cap:severity&gt;Minor&lt;/cap:severity&gt;
  &lt;cap:certainty&gt;Observed&lt;/cap:certainty&gt;
  &lt;cap:areaDesc&gt;Catahoula; Concordia; East Carroll; Franklin; Madison; Morehouse; Richland; Tensas; West Carroll&lt;/cap:areaDesc&gt;
  &lt;cap:polygon&gt;&lt;/cap:polygon&gt;
  &lt;cap:geocode&gt;
  &lt;valueName&gt;FIPS6&lt;/valueName&gt;
  &lt;value&gt;022025 022029 022035 022041 022065 022067 022083 022107 022123&lt;/value&gt;
  &lt;valueName&gt;UGC&lt;/valueName&gt;
  &lt;value&gt;LAZ007 LAZ008 LAZ009 LAZ015 LAZ016 LAZ023 LAZ024 LAZ025 LAZ026&lt;/value&gt;
  &lt;/cap:geocode&gt;
  &lt;cap:parameter&gt;
  &lt;valueName&gt;VTEC&lt;/valueName&gt;
  &lt;value&gt;&lt;/value&gt;
  &lt;/cap:parameter&gt;
  &lt;/entry&gt;
  &lt;/feed&gt;
  </code></pre>
  
  <p>Thanks so much for any help or suggestions. -TK</p>