title: Getting CDATA XML Section Using Linq
body: <p>I have searched around looking for ways to get at the CDATA section text area and found very luk warm solutions using linq. I need to extract the XML imbedded in the CDATA Section so I can pull out different pieces of info. I have the following XML: </p>
  
  <pre><code>&lt;Envelope&gt;
   &lt;Warehouse /&gt;
   &lt;Payload&gt;
    - &lt;![CDATA[ 
      &lt;?xml version="1.0"?&gt;
      &lt;ROOT&gt;
        &lt;ORDERID&gt;399798&lt;/ORDERID&gt;
        &lt;PRODUCTNUMBER&gt;00003997&lt;/PRODUCTNUMBER&gt;
        &lt;DESCIPTION&gt;Red Rider BB-Gun&lt;/DESCIPTION&gt;
        &lt;STATUS&gt;InStock&lt;/STATUS&gt;
        &lt;LOCATION&gt;Chicago&lt;/LOCATION&gt;
      &lt;/ROOT&gt; ]]&gt;
   &lt;/Payload&gt;
  &lt;/Envelope&gt;
  </code></pre>
  
  <p>So I would like if possible to do this by extracting the whole cdata section into an XDocument so I can use Linq to query. Also if I just wanted to pull out a single Element from the CData section. How can I do this? Using Linq?  </p>
  
  <p>I have tried using this Linq code below to give me back cdata section but can't do anything with it since it comes back as an IEnumerable. I'm probably missing something easy so I come to you the Linq wizards for some help.</p>
  
  <p>Here's the code I mentioned:</p>
  
  <pre><code> var queryCDATAXML = from el in xdoc.DescendantNodes()
                       where el.NodeType == XmlNodeType.CDATA
                       select el.Parent.Value.Trim();
  </code></pre>
  
  <p>Is there a way to do a select new XDocument or XmlDocument like so:</p>
  
  <pre><code>//This doesn't compile.
   var queryCDATAXML = from el in xdoc.DescendantNodes()
                              where el.NodeType == XmlNodeType.CDATA
                              select new XDocument()
                                {  
                                   el.Parent.Value.Trim();
                                }   
  </code></pre>
  
  <p>If I am going about this all wrong or their is a better way to accomplish this I'm open for suggestions. :)</p>
  
  <p>Thanks,
  DND </p>
  
  <p>Code Update:</p>
  
  <pre><code>var queryCDATAXML = from el in xdoc.DescendantNodes()
                       where el.NodeType == XmlNodeType.CDATA
                       select el.Parent.Value.Trim();
  
  var xdoc = XDocument.Parse(queryCDATAXML);
  </code></pre>
  
  <p>Generates this error:
  Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'. </p>