title: sequence contains no elements while parsing XML using Linq
body: <p>I have a XML Like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;soap:Body&gt;
          &lt;SampleResponse xmlns="http://tempuri.org/"&gt;
              &lt;SampleResult&gt;
                  &lt;diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
                                   xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"&gt;
                      &lt;NewDataSet xmlns=""&gt;
                          &lt;Table diffgr:id="Table1" msdata:rowOrder="0"&gt;
                              &lt;tag1&gt;tag1 text&lt;/tag1&gt;
                              &lt;tag2&gt;tag2 text&lt;/tag2&gt;
                          &lt;/Table&gt;
                          &lt;Table diffgr:id="Table2" msdata:rowOrder="1"&gt;
                              &lt;tag1&gt;tag1 text&lt;/tag1&gt;
                              &lt;tag2&gt;tag2 text&lt;/tag2&gt;
                          &lt;/Table&gt;
                      &lt;/NewDataSet&gt;
                  &lt;/diffgr:diffgram&gt;
              &lt;/SampleResult&gt;
          &lt;/SampleResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>here i am parsing above XML Like Below:</p>
  
  <pre><code>   // My parser Class
      class ParseClass 
      { 
          public string tag1 { get; set; }
          public string tag2 { get; set; }
      }
  </code></pre>
  
  <p>My parsing Code is:   </p>
  
  <pre><code> string XMLresponse = e.response;
      var XResult = XElement.Parse(XMLresponse);
      var result = XResult.Descendants("Table").Select(t =&gt; new ParseClass
                   {
                       tag1 = t.Descendants("tag1").First().Value,
                       tag2 = t.Descendants("tag2").First().Value,
                   });
  foreach (var res in result1)
                      {
  string str=res.tag1;
  str=res.tag2;
                      }
  </code></pre>
  
  <p>I am able parse above XML successfully if all the tags are coming. But some times my response XML is missing tag called tag2, at that time i am not able to parse the XML and giving exception like <strong>"sequence contains no elements"</strong>.</p>
  
  <p><strong>Here my requirement is:</strong>
  I have tried FirstOrDefault method in place of First method but no use.
  <strong>if any tag is missing in XML then that variable should be Null for that Object(i.e: if tag2 is missing then res.tag2 should be null). How can i achieve this?</strong> </p>