title: XDocument and Linq returns null if the element has xmlns attribute
body: <p>Newbie with XDocuments and Linq, please suggest a solution to retrieve the data from a particular tag in the xml string:</p>
  
  <p>If I have a XML string from webservice response (I formatted xml for ease):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/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;GetCashFlowReportResponse xmlns="http://tempuri.org/"&gt;
        &lt;GetCashFlowReportPdf&gt;Hello!&lt;/GetCashFlowReportPdf&gt;
      &lt;/GetCashFlowReportResponse&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Using the following code, I can get the value only if <code>GetCashFlowReportResponse</code> tag doesn't have <code>"xmlns"</code> attribute. Not sure why? Otherwise, it always return null.</p>
  
  <pre><code>string inputString = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/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;GetCashFlowReportResponse xmlns=\"http://tempuri.org/\"&gt;&lt;GetCashFlowReportPdf&gt;Hello!&lt;/GetCashFlowReportPdf&gt;&lt;/GetCashFlowReportResponse&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;"    
  XDocument xDoc = XDocument.Parse(inputString);
  //XNamespace ns = "http://tempuri.org/";
  XNamespace ns = XNamespace.Get("http://tempuri.org/");
  
  var data = from c in xDoc.Descendants(ns + "GetCashFlowReportResponse")
             select (string)c.Element("GetCashFlowReportPdf");
  
  foreach (string val in data)
  {
      Console.WriteLine(val);
  }
  </code></pre>
  
  <p>I can't change the web service to remove that attribute. IS there a better way to read the response and get the actual data back to the user (in more readable form)?</p>
  
  <p>Edited: 
  <strong>SOLUTION:</strong></p>
  
  <pre><code>XDocument xDoc = XDocument.Parse(inputString);
  XNamespace ns = "http://tempuri.org/";
  
  var data = from c in xDoc.Descendants(ns + "GetCashFlowReportResponse")
             select (string)c.Element(ns + "GetCashFlowReportPdf");
  foreach (string val in data)
  {
     Console.WriteLine(val);
  }
  </code></pre>
  
  <p>Note: Even if all the child elements doesn't have the namespace attribute, the code will work if you add the "ns" to the element as I guess childs inherit the namespace from parent (see response from SLaks).</p>