XML
Beginner
1 min read
CDATA Sections and Comments
Example
<?xml version="1.0" encoding="UTF-8"?>
<snippets>
<!-- This is an XML comment. Double-hyphen (--) is not allowed inside. -->
<!-- CDATA section: embed HTML without escaping -->
<htmlFragment><![CDATA[
<div class="box">
<p>Hello <strong>World</strong></p>
<a href="http://example.com?a=1&b=2">Link</a>
</div>
]]></htmlFragment>
<!-- CDATA section: embed SQL -->
<query><![CDATA[
SELECT id, name
FROM users
WHERE age > 18 AND status = 'active'
ORDER BY name ASC;
]]></query>
<!-- Processing instruction targeting a stylesheet -->
<?xml-stylesheet type="text/css" href="style.css"?>
<!-- Regular text needs entity references -->
<escaped>if (a < b && c > 0) { }</escaped>
</snippets>