Horje
XML - CDATA Sections

CDATA sections are a mechanism in XML for handling character data that might otherwise be misinterpreted by the XML parser. CDATA stands for Character Data. These sections include blocks of text within an XML document that the parser should treat literally, without interpreting any characters as XML markup. This is helpful when the text contains characters that would normally have special meaning in XML, such as < (less than sign) > (greater than sign) and & (ampersand).

Syntax:

<![CDATA[  
characters with markup
]]>

where:

  • <![CDATA[: CDATA Start section
  • ]]>: CDATA End section

Rules for CDATA

  • No Nesting: You cannot have CDATA sections nested within other CDATA sections as it will be invalid.
  • No “]]>” Inside: The string sequence “]]>” cannot appear within the CDATA section itself, as it would be misinterpreted as the closing delimiter and can cause parsing errors.

Example: The example below shows an example of CDATA, each character written inside the CDATA section is ignored by the parser. everything between <message> and </message> is treated as character data and not as markup.

XML
<script> 
    /* <![CDATA[ */ 
    let message = "This is a message with < and > symbols"; 
    /* ]]> */ 
    console.log(message); 
</script>

Output:

This is a message with < and > symbols



Reffered: https://www.geeksforgeeks.org


Web Technologies

Related
Two Way Data Binding in javascript Two Way Data Binding in javascript
Prompt Engineering Tips with GitHub Copilot Prompt Engineering Tips with GitHub Copilot
How to Add an Author Bio to WordPress Posts? How to Add an Author Bio to WordPress Posts?
How to Add a Link to Wordpress Page? How to Add a Link to Wordpress Page?
How to Check Apache Version? How to Check Apache Version?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13