title: Remove all CDATA nodes and replace with encoded text
body: <p>So, I've got a massive XML file and I want to remove all CDATA sections and replace the CDATA node contents with safe, html encoded text nodes. </p>
  
  <p>Just stripping out the CDATA with a regex will of course break the parsing. Is there a LINQ or XmlDocument or XmlTextWriter technique to swap out the CDATA with encoded text?</p>
  
  <p>I'm not too concerned with the final encoding quite yet, just how to replace the sections with the encoding of my choice. </p>
  
  <p>Original Example</p>
  
  <pre><code>  ---
    &lt;COLLECTION type="presentation" autoplay="false"&gt;
      &lt;TITLE&gt;&lt;![CDATA[Rights &amp; Responsibilities]]&gt;&lt;/TITLE&gt;
      &lt;ITEM id="2802725d-dbac-e011-bcd6-005056af18ff" presenterGender="male"&gt;
        &lt;TITLE&gt;&lt;![CDATA[Watch the demo]]&gt;&lt;/TITLE&gt;
        &lt;LINK&gt;&lt;![CDATA[_assets/2302725d-dbac-e011-bcd6-005056af18ff/presentation/presentation-00000000.mp4]]&gt;&lt;/LINK&gt;
      &lt;/ITEM&gt;
    &lt;/COLLECTION&gt;
    ---
  </code></pre>
  
  <p>Sould Become</p>
  
  <pre><code>          &lt;COLLECTION type="presentation" autoplay="false"&gt;
              &lt;TITLE&gt;Rights &amp;amp; Responsibilities&lt;/TITLE&gt;
              &lt;ITEM id="2802725d-dbac-e011-bcd6-005056af18ff" presenterGender="male"&gt;
                &lt;TITLE&gt;Watch the demo&lt;/TITLE&gt;
                &lt;LINK&gt;_assets/2302725d-dbac-e011-bcd6-005056af18ff/presentation/presentation-00000000.mp4&lt;/LINK&gt;
              &lt;/ITEM&gt;
            &lt;/COLLECTION&gt;
  </code></pre>
  
  <p>I guess the ultimate goal is to move to JSON. I've tried this</p>
  
  <pre><code>            XmlDocument doc = new XmlDocument();
              doc.Load(Server.MapPath( @"~/somefile.xml"));
              string jsonText = JsonConvert.SerializeXmlNode(doc);
  </code></pre>
  
  <p>But I end up with ugly nodes, i.e. "#cdata-section" keys. It would take WAAAAY to many hours to have the front end re-developed to accept this.</p>
  
  <pre><code>"COLLECTION":[{"@type":"whitepaper","TITLE":{"#cdata-section":"SUPPORTING DOCUMENTS"}},{"@type":"presentation","@autoplay":"false","TITLE":{"#cdata-section":"Demo Presentation"},"ITEM":{"@id":"2802725d-dbac-e011-bcd6-005056af18ff","@presenterGender":"male","TITLE":{"#cdata-section":"Watch the demo"},"LINK":{"#cdata-section":"_assets/2302725d-dbac-e011-bcd6-005056af18ff/presentation/presentation-00000000.mp4"}
  </code></pre>