I'm trying to wrap the inner text of script tags into CDATA section.
I have the following code already (which I copied from another side) but works partial :
Regex regScriptCDATA = new Regex("(<script[^<>]*>)([^<>]+)(<\\/script>)");
MatchCollection m = regScriptCDATA.Matches(strHtml);
String strScriptCDATA = "$1" + "//<![CDATA[\n" + "$2" + "//]]>\n" + "$3";
strHtml = regScriptCDATA.Replace(strHtml, strScriptCDATA);
My problem is that if the text contains < or > it won't wrap.
The problem is that I have a website which (still) needs to be XHTML compatible. It's an ASP.NET application with hundreds of usercontrols which have script inside their markup sometimes wrapped into CDATA.
Instead of modifying each usercontrol and putting CDATA into these scripts I was thinking of modifying the HTML by replacing the script tags which don't have CDATA before rendering the site.
Using regular expressions would be preferable.