1. CDATA is still
part of the document
, while a comment is not
2. In CDATA we cannot include the string
]]>
, while in a comment
--
3. CDATA content is visible on the web if we specify
xmlns
attribute as
http://www.w3.org/1999/xhtml
, even if the file is saved as
.xml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CDATA Example</title>
</head>
<body>
<h2>Using a Comment</h2>
<div id="commentExample">
<!--
You won't see this in the document
and can use reserved characters like
< > & "
-->
</div>
<h2>Using a CDATA Section</h2>
<div id="cdataExample">
<![CDATA[
You will see this in the document
and can use reserved characters like
< > & "
]]>
</div>
</body>
</html>