title: Parse data from Soap Envelop request
body: <p>I have soap envelope request and I want to extract some data from element.</p>
  <p>Below is a soap envelope request in a string format and I want to extract data that is resides under &quot;&lt;![CDATA[[datafile]&quot;. Is there any way I can do that?</p>
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:ns=&quot;http://ACORD.org/Standards/Life/445&quot; xmlns:aaa=&quot;http://Life/PolicyDetails/3&quot; xmlns:date=&quot;http://exslt.org/dates-and-times&quot;&gt;
      &lt;soapenv:Header/&gt;
      &lt;soapenv:Body&gt;
          &lt;aaa:getPolicyDetailResponse&gt;
              &lt;policyInfoResp&gt;
                  &lt;ns:TXLife&gt;
                      
                      &lt;ns:TXLifeResponse PrimaryObjectID=&quot;Holding_1&quot;&gt;
                          &lt;ns:TransRefGUID&gt;rsf4--41c3-8981-5a2c4518a7&lt;/ns:TransRefGUID&gt;
                          &lt;ns:TransType tc=&quot;201&quot;&gt;Inforce Policy Inquiry&lt;/ns:TransType&gt;
                          &lt;ns:TransExeDate&gt;2020-10-27-05:00&lt;/ns:TransExeDate&gt;
                          &lt;ns:TransExeTime&gt;00:49:16-05:00&lt;/ns:TransExeTime&gt;
                          &lt;ns:TransMode tc=&quot;2&quot;&gt;Original&lt;/ns:TransMode&gt;
                          &lt;ns:NoResponseOK tc=&quot;0&quot;&gt;False&lt;/ns:NoResponseOK&gt;
                          &lt;ns:TestIndicator tc=&quot;0&quot;&gt;False&lt;/ns:TestIndicator&gt;           
                          &lt;ns:OLifEExtension VendorCode=&quot;AG&quot; ExtensionCode=&quot;INI&quot;&gt;
                              &lt;![CDATA[
                              &lt;![CDATA[[datafile]
  Agent.CityState=ATLANTA, GA
  Agent.Comp=AGL
  Agent.Name=YRVFL KYCHBPO K               
  Agent.Number=000B078A
  Agent.Status=Inactive
  Agent.StrAddr=4286 DIGKGWZ DNVK KO DYG 202            
  ]]]]&gt;
                              &lt;![CDATA[&gt;]]&gt;
                          &lt;/ns:OLifEExtension&gt;
                      &lt;/ns:TXLifeResponse&gt;
                  &lt;/ns:TXLife&gt;
              &lt;/policyInfoResp&gt;
          &lt;/aaa:getPolicyDetailResponse&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  <p>Below is the code I wrote to parse data but I am getting null reference exception.</p>
  <pre><code>string contents = System.IO.File.ReadAllText(@&quot;C:\Users\reg\CaReg-output1.txt&quot;);
                  var document = XDocument.Parse(contents);
                  string url = &quot;http://ACORD.org/Standards/Life/2&quot;;
                  var ns = XNamespace.Get(url);
                  var xElements = document.Element(ns+&quot;OLifEExtension&quot;).Value.ToString();
  </code></pre>