No, The markup denoting a CDATA Section is not permitted as the value of an attribute.

According to the specification, this prohibition is indirect rather than direct. The spec says that the Attribute value must not have an open angle bracket. Open angle brackets and ampersand must be escaped. Therefore you cannot insert a CDATA section. womp womp.

A CData Section is interpreted only when it is in a text node of an element.

Answer from JMP on Stack Overflow

No, The markup denoting a CDATA Section is not permitted as the value of an attribute.

According to the specification, this prohibition is indirect rather than direct. The spec says that the Attribute value must not have an open angle bracket. Open angle brackets and ampersand must be escaped. Therefore you cannot insert a CDATA section. womp womp.

A CData Section is interpreted only when it is in a text node of an element.

Answer from JMP on Stack Overflow
🌐
Wikipedia
en.wikipedia.org › wiki › CDATA
CDATA - Wikipedia
January 13, 2026 - and an XML parser would interpret the a attribute's value as being the character data 1 & 2 are < 3. An SGML or XML DTD may also include entity declarations in which the token CDATA is used to indicate that entity consists of character data. The character data may appear within the declaration itself or may be available externally, referenced by a URI.
🌐
W3Resource
w3resource.com › xml › CDATA-sections.php
XML CDATA - w3resource
November 7, 2025 - For all CDATA, the character literals which are prohibited, are not characters which are not literals and since they are not, it causes problems for exporting data in the form of other datasets like executing Processing Instructions. ... Use of the built-in entity &apos; inside attribute content.
🌐
TutorialsPoint
tutorialspoint.com › xml › xml_cdata_sections.htm
XML - CDATA Sections
In this chapter, we will discuss XML CDATA section. The term CDATA means, Character Data. CDATA is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › xml tutorial › xml cdata
XML CDATA | How CDATA works in XML with Examples
April 5, 2023 - XML Character data (CDATA) is defined as Blocks of texts and a type of XML Node recognized by the mark-up languages but are not parsed by the parsers. This is used to solve the inclusion of the mathematical term in the XML document.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
CData
cdn.cdata.com › help › AZH › mft › XML-Map-XML-Attributes.html
CData Arc - XML Attributes | Version 22.0.8473
When enabled, the designer will display any attributes detected as a child of the element the attribute belongs to. All XML attributes are named with a ‘@’ prefix (the ‘@’ symbol is not a valid character in an XML element name).
🌐
GeeksforGeeks
geeksforgeeks.org › html › xml-cdata-sections
XML - CDATA Sections - GeeksforGeeks
July 23, 2025 - 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 ...
🌐
RexTheme
rextheme.com › docs › how-to-include-cdata-in-an-xml-feed-attribute-tag-2
How To Include CDATA In An XML Feed Attribute Tag » RexTheme
June 21, 2024 - 3. Click on the Output Filter dropdown field of the concerned attribute and select “CDATA” from the dropdown list. 4. Finally, go back to the top and click on the publish/ update button to publish/ update the feed. Now when you open the feed, you will find that the values of the concerned attributes are within the <!CDATA[ …
Find elsewhere
Top answer
1 of 13
1263

CDATA stands for Character Data and it means that the data in between these strings includes data that could be interpreted as XML markup, but should not be.

The key differences between CDATA and comments are:

  • As Richard points out, CDATA is still part of the document, while a comment is not.
  • In CDATA you cannot include the string ]]> (CDEnd), while in a comment -- is invalid.
  • Parameter Entity references are not recognized inside of comments.

This means given these four snippets of XML from one well-formed document:

<!ENTITY MyParamEntity "Has been expanded">

<!--
Within this comment I can use ]]>
and other reserved characters like <
&, ', and ", but %MyParamEntity; will not be expanded
(if I retrieve the text of this node it will contain
%MyParamEntity; and not "Has been expanded")
and I can't place two dashes next to each other.
-->

<![CDATA[
Within this Character Data block I can
use double dashes as much as I want (along with <, &, ', and ")
*and* %MyParamEntity; will be expanded to the text
"Has been expanded" ... however, I can't use
the CEND sequence. If I need to use CEND I must escape one of the
brackets or the greater-than sign using concatenated CDATA sections.
]]>

<description>An example of escaped CENDs</description>
<!-- This text contains a CEND ]]> -->
<!-- In this first case we put the ]] at the end of the first CDATA block
     and the > in the second CDATA block -->
<data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data>
<!-- In this second case we put a ] at the end of the first CDATA block
     and the ]> in the second CDATA block -->
<alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative>
2 of 13
377

A CDATA section is "a section of element content that is marked for the parser to interpret as only character data, not markup."

Syntactically, it behaves similarly to a comment:

<exampleOfAComment>
<!--
    Since this is a comment
    I can use all sorts of reserved characters
    like > < " and &
    or write things like
    <foo></bar>
    but my document is still well-formed!
-->
</exampleOfAComment>

... but it is still part of the document:

<exampleOfACDATA>
<![CDATA[
    Since this is a CDATA section
    I can use all sorts of reserved characters
    like > < " and &
    or write things like
    <foo></bar>
    but my document is still well formed!
]]>
</exampleOfACDATA>

Try saving the following as a .xhtml file (not .html) and open it using FireFox (not Internet Explorer) to see the difference between the comment and the CDATA section; the comment won't appear when you look at the document in a browser, while the CDATA section will:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<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>

Something to take note of with CDATA sections is that they have no encoding, so there's no way to include the string ]]> in them. Any character data which contains ]]> will have to - as far as I know - be a text node instead. Likewise, from a DOM manipulation perspective you can't create a CDATA section which includes ]]>:

var myEl = xmlDoc.getElementById("cdata-wrapper");
myEl.appendChild(xmlDoc.createCDATASection("This section cannot contain ]]>"));

This DOM manipulation code will either throw an exception (in Firefox) or result in a poorly structured XML document: http://jsfiddle.net/9NNHA/

🌐
W3Resource
w3resource.com › xml › attribute.php
XML Attribute - w3resource
November 7, 2025 - Any attribute value must consist of one of the following types of attributes available to an XML document. ... <sometext> <![CDATA[ They're saying "x < y" & that "z > y" so I guess that means that z > x ]]> </sometext>
🌐
Novixys Software
novixys.com › blog › what-does-cdata-in-xml-mean
What does <![CDATA[]]> in XML mean? | Novixys Software Dev Blog
January 4, 2017 - This declaration states that an img element must have a src attribute whose value type is CDATA. CDATA sections are used when larger amounts of verbatim text need to appear within XML documents and processed verbatim.
🌐
CData
cdn.cdata.com › help › AZK › mft › XML-Map-XML-Attributes.html
CData Arc - XML Attributes | Version 24.3.9159
Destination templates that include XML attributes display the attribute nodes as children of the element they belong to, and these nodes can be mapped just like any other value.
🌐
Coderanch
coderanch.com › t › 465027 › certification › declare-attribute-xml-element-CDATA
How to declare an attribute of xml element as CDATA type (Certifications forum at Coderanch)
October 3, 2009 - If you serialize your xml document yourself you just have to embed the password in a CDATA section. Anyway you have to make sure the password does not contain ]]>. ... Thanks for helps, but i could not embed "<!CDATA[[.....]]" in the attribute, the "><" in attribute is not allowed, i think it should be legal to use the "<!CDATA[[.....]]" in the element value.
🌐
W3Schools
w3schools.com › xml › dom_cdatasection.asp
XML DOM - CDATASection object
A CDATA section contains text that will NOT be parsed by a parser. Tags inside a CDATA section will NOT be treated as markup and entities will not be expanded. The primary purpose is for including material such as XML fragments, without needing ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › visual-basic › language-reference › xml-literals › xml-cdata-literal
XML CDATA Literal - Visual Basic | Microsoft Learn
September 15, 2021 - XML CDATA sections contain raw text that should be included, but not parsed, with the XML that contains it. A XML CDATA section can contain any text. This includes reserved XML characters. The XML CDATA section ends with the sequence "]]>".
🌐
CData
cdn.cdata.com › help › AZJ › mft › XML-Map-XML-Attributes.html
CData Arc - XML Attributes | Version 23.4.8839
Destination templates that include XML attributes display the attribute nodes as children of the element they belong to, and these nodes can be mapped just like any other value.
🌐
Quackit
quackit.com › xml › tutorial › xml_cdata.cfm
XML CDATA
In a previous lesson, we learned how to escape a single character by using an entity reference. In this lesson, we'll look at how to escape a whole block of text — not just a single character. In XML, a CDATA section is used to escape a block of text that would otherwise be parsed as markup.
🌐
Devzery
devzery.com › post › cdata-in-xml-a-comprehensive-guide-for-developers
CDATA in XML: A Comprehensive Guide for Developers
August 28, 2024 - CDATA stands for Character Data, and it is used in XML to include blocks of text that should not be parsed by the XML parser as XML elements or attributes.
🌐
Reddit
reddit.com › r/xml › how can i print attribute value in its cdata?
r/xml on Reddit: How can I print attribute value in its CDATA?
July 23, 2021 -

Let me give an example

<head>
    <body string="WORLD">
        <![CDATA[ HELLO {} ]]>
    </body>
</head>

you see the {} next to HELLO, what I want is to replace it with value string which is "WORLD" , so that if I print the body I get HELLO WORLD as output?

Can we do that in XML?

Or suggest me something other way to do in other language