I think that there is no real difference. I prefer to use CDATA for everything because I don't have to care about the characters to escape and the only thing I must take care of are the "]]>" in the content, which btw ARE allowed if you split the CDATA opening and closing tags into multiple fragments.
Example (in PHP)
<?php
function getXMLContent($content)
{
if
(
(strpos($content, '<') !== false) ||
(strpos($content, '>') !== false) ||
(strpos($content, '&') !== false) ||
(strpos($content, '"') !== false) ||
(strpos($content, '\'') !== false)
)
{
// If value contains ']]>', we need to break it into multiple CDATA tags
return "<![CDATA[". str_replace(']]>', ']]]]><![CDATA[>', $content) ."]]>";
}
else
{
// Value does not contain any special characters which needs to be wrapped / encoded / escaped
return $content;
}
}
echo getXMLContent("Hello little world!");
echo PHP_EOL . PHP_EOL;
echo getXMLContent("This < is > a & hard \" test ' for ]]> XML!");
?>
Returns
Hello little world!
<![CDATA[This < is > a & hard " test ' for ]]]]><![CDATA[> XML!]]>
If you put that into a XML structure like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test>
<![CDATA[This < is > a & hard " test ' for ]]]]><![CDATA[> XML!]]>
</test>
... save it to a file (like test.xml) and open it with a browser, you'll see, that the browser (or any other XML application / parser) will show you the correct ouput string:
This < is > a & hard " test ' for ]]> XML!