Search code examples
htmlxmlcdatapre

CDATA not working for C++ code inside a <pre> tag


I have a problem with outputting some C++ inside a pre tag.

The XHTML code I have is :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
   <head>   
      <meta http-equiv="Content-Type" content="application/xhtml+xml" />
   </head>
   <body>
   <pre><![CDATA[
   #include <cstdio> 

   int x = 1;
   ]]></pre>
   </body>
</html>

But when I try to view the webpage I only see

int x = 1;
]]>

and not

#include <cstdio> 

int x = 1;

as I want to.

What don't I understand about CDATA behaviour ?


Solution

  • CDATA is not an HTML construct; it is an XML (and XHTML) construct.