Python CDATA Sections & XML Comments
A CDATA (Character Data) section tells the XML parser to treat everything inside as pure raw text rather than XML markup. This allows embedding code snippets, SQL queries, and HTML with unescaped < and & characters directly.
"A CDATA block is like a sealed biohazard container for raw code: the XML inspector sees the container and allows it through without analyzing or parsing anything inside."
Deep Dive: How It Works
CDATA Syntax: <![CDATA[ raw unescaped text here ]]>
No Parsing Inside CDATA: Characters like <, >, and & are not evaluated as markup.
XML Comments: <!-- Comment text --> (cannot contain double hyphens -- inside).
Syntax Blueprint
<script><![CDATA[ if (x < 10 && y > 20) { ... } ]]></script>Everything between <![CDATA[ and ]]> is ignored by the XML parser.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Attempting to nest CDATA blocks.Why it happens: The first ]]> immediately closes the entire CDATA section, leaving subsequent tokens as malformed XML.
How to fix: Never nest CDATA sections; terminate and re-open if necessary.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Wrap code in a CDATA section
Inside <codeSnippet>, wrap `if (a < b && b > 0)` inside `<![CDATA[ ... ]]>`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.