What does in XML mean?what does <![CDATA[<![CDATA[some text]]]]><![CDATA[>]]> in XML mean?What's the use of <!CDATA[]> in xml?When is a CDATA section necessary within a script tag?How to pass variables and data from PHP to JavaScript?Is there a way to escape a CDATA end token in xml?Encode NSString for XML/HTMLNested comments in XML?XML Validation error : EntityRef: expecting';'java.lang.IllegalStateException: CDATA tags may not nestEscape multiple “%” characters in AndroidWhen is a CDATA section necessary within a script tag?Best way to compare 2 XML documents in Java<, > in xml documentCan you provide some examples of why it is hard to parse XML and HTML with a regex?What characters do I need to escape in XML documents?What does “xmlns” in XML mean?How do you parse and process HTML/XML in PHP?Reading XML CDATA section with ]] in itParsing XML CDATA Blockswhat does <![CDATA[<![CDATA[some text]]]]><![CDATA[>]]> in XML mean?
Numerical second order differentiation
How to write a nice frame challenge?
First occurrence in the Sixers sequence
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
Schedule Batch Apex too many rows
Does anyone recognize these rockets, and their location?
How did space travel spread through the galaxy?
Can "Es tut mir leid" be used to express empathy rather than remorse?
How "fast" does astronomical events happen?
My husband's visa refused but mine wasn't -- can I travel?
Is my research statement supposed to lead to papers in top journals?
How can this shape perfectly cover a cube?
How to sort human readable size
How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?
Is this set open or closed (or both?)
Background for black and white chart
How do I gain the trust of other PCs?
How do I become a better writer when I hate reading?
How do credit card companies know what type of business I'm paying for?
Why are almost all the people in this orchestra recording wearing headphones with one ear on and one ear off?
How to avoid offending original culture when making conculture inspired from original
Catching a robber on one line
How to address players struggling with simple controls?
How can the US president give an order to a civilian?
What does in XML mean?
what does <![CDATA[<![CDATA[some text]]]]><![CDATA[>]]> in XML mean?What's the use of <!CDATA[]> in xml?When is a CDATA section necessary within a script tag?How to pass variables and data from PHP to JavaScript?Is there a way to escape a CDATA end token in xml?Encode NSString for XML/HTMLNested comments in XML?XML Validation error : EntityRef: expecting';'java.lang.IllegalStateException: CDATA tags may not nestEscape multiple “%” characters in AndroidWhen is a CDATA section necessary within a script tag?Best way to compare 2 XML documents in Java<, > in xml documentCan you provide some examples of why it is hard to parse XML and HTML with a regex?What characters do I need to escape in XML documents?What does “xmlns” in XML mean?How do you parse and process HTML/XML in PHP?Reading XML CDATA section with ]] in itParsing XML CDATA Blockswhat does <![CDATA[<![CDATA[some text]]]]><![CDATA[>]]> in XML mean?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I often find this strange CDATA tag in XML files:
<![CDATA[some stuff]]>
I have observed that this CDATA tag always comes at the beginning, and then followed by some stuff.
But sometimes it is used, sometimes it is not. I assume it is to mark that some stuff is the "data" that will be inserted after that. But what kind of data is some stuff? Isn't anything I write in XML tags some sort of data?
xml cdata
add a comment |
I often find this strange CDATA tag in XML files:
<![CDATA[some stuff]]>
I have observed that this CDATA tag always comes at the beginning, and then followed by some stuff.
But sometimes it is used, sometimes it is not. I assume it is to mark that some stuff is the "data" that will be inserted after that. But what kind of data is some stuff? Isn't anything I write in XML tags some sort of data?
xml cdata
add a comment |
I often find this strange CDATA tag in XML files:
<![CDATA[some stuff]]>
I have observed that this CDATA tag always comes at the beginning, and then followed by some stuff.
But sometimes it is used, sometimes it is not. I assume it is to mark that some stuff is the "data" that will be inserted after that. But what kind of data is some stuff? Isn't anything I write in XML tags some sort of data?
xml cdata
I often find this strange CDATA tag in XML files:
<![CDATA[some stuff]]>
I have observed that this CDATA tag always comes at the beginning, and then followed by some stuff.
But sometimes it is used, sometimes it is not. I assume it is to mark that some stuff is the "data" that will be inserted after that. But what kind of data is some stuff? Isn't anything I write in XML tags some sort of data?
xml cdata
xml cdata
edited Aug 28 '17 at 0:43
jpaugh
4,05132670
4,05132670
asked May 6 '10 at 20:20
dontWatchMyProfiledontWatchMyProfile
19.7k47161253
19.7k47161253
add a comment |
add a comment |
12 Answers
12
active
oldest
votes
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 three 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>
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
You have to have two CDATA sections to concatenate the]]and the>- see this answer for the hows and the whys.
– Sean Vieira
Sep 26 '15 at 17:21
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
So this piece of C-like code could not easily be put in a CDATA section:if (a[b[c]]>10).
– Anders Tornblad
Mar 22 '17 at 9:43
|
show 5 more comments
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/
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
|
show 3 more comments
One big use-case: your xml includes a program, as data (e.g. a web-page tutorial for Java). In that situation your data includes a big chunk of characters that include '&' and '<' but those characters aren't meant to be xml.
Compare:
<example-code>
while (x < len && !done)
print( "Still working, 'zzz'." );
++x;
</example-code>
with
<example-code><![CDATA[
while (x < len && !done)
print( "Still working, 'zzzz'." );
++x;
]]></example-code>
Especially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. As @paary mentioned, other common uses include when you're embedding URLs that contain ampersands. Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file.
(I suspect all the comparisons to comments are kinda misleading/unhelpful.)
add a comment |
I once had to use CDATA when my xml element needed to store HTML code. Something like
<codearea>
<![CDATA[
<div> <p> my para </p> </div>
]]>
</codearea>
So CDATA means it will ignore any character which could otherwise be interpreted as XML tag like < and > etc.
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
add a comment |
The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
add a comment |
From Wikipedia:
[In] an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup.
http://en.wikipedia.org/wiki/CDATA
Thus: text inside CDATA is seen by the parser but only as characters not as XML nodes.
add a comment |
As another example of its use:
If you have an RSS Feed (xml document) and want to include some basic HTML encoding in the display of the description, you can use CData to encode it:
<item>
<title>Title of Feed Item</title>
<link>/mylink/article1</link>
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</item>
The RSS Reader pulls in the description and renders the HTML within the CDATA.
Note - not all HTML tags work - I think it depends on the RSS reader you are using.
And as a explanation for why this example uses CData (and not the appropriate pubData and dc:creator tags): this is for website display using a RSS widget for which we have no real formatting control.
This enables us to specify the height and position of the included image, format the author names and date correctly, and so forth, without the need for a new widget. It also means I can script this and not have to add them by hand.
add a comment |
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed.
For example, if you want to pass a URL that contains & in it, you can use CDATA to do it. Otherwise, you will get an error as it will be parsed as regular XML.
add a comment |
It's used to contain data which could otherwise be seen as xml because it contains certain characters.
This way the data inside will be displayed, but not interpreted.
add a comment |
Usually used for embedding custom data, like pictures or sound data within an XML document.
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
add a comment |
The Cdata is a data which you may want to pass to an xml parser and still not interpreted as an xml.
Say for eg :- You have an xml which has encapsulates question/answer object . Such open fields can have any data which does not strictly fall under basic data type or xml defined custom data types. Like --Is this a correct tag for xml comment ? .--
You may have a requirement to pass it as it is without being interpreted by the xml parser as another child element. Here Cdata comes to your rescue . By declaring as Cdata you are telling the parser don't treat the data wrapped as an xml (though it may look like one )
add a comment |
It escapes a string that cannot be passed to XML as usual:
Example:
The string contains "&" in it.
You can not:
<FL val="Company Name">Dolce & Gabbana</FL>
Therefore, you must use CDATA:
<FL val="Company Name"> <![CDATA["Dolce & Gabbana"]]> </FL>
add a comment |
protected by Aniket Thakur Aug 4 '15 at 12:16
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 three 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>
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
You have to have two CDATA sections to concatenate the]]and the>- see this answer for the hows and the whys.
– Sean Vieira
Sep 26 '15 at 17:21
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
So this piece of C-like code could not easily be put in a CDATA section:if (a[b[c]]>10).
– Anders Tornblad
Mar 22 '17 at 9:43
|
show 5 more comments
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 three 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>
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
You have to have two CDATA sections to concatenate the]]and the>- see this answer for the hows and the whys.
– Sean Vieira
Sep 26 '15 at 17:21
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
So this piece of C-like code could not easily be put in a CDATA section:if (a[b[c]]>10).
– Anders Tornblad
Mar 22 '17 at 9:43
|
show 5 more comments
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 three 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>
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 three 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>
edited May 23 '17 at 12:10
Community♦
11
11
answered May 6 '10 at 20:23
Sean VieiraSean Vieira
118k24234238
118k24234238
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
You have to have two CDATA sections to concatenate the]]and the>- see this answer for the hows and the whys.
– Sean Vieira
Sep 26 '15 at 17:21
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
So this piece of C-like code could not easily be put in a CDATA section:if (a[b[c]]>10).
– Anders Tornblad
Mar 22 '17 at 9:43
|
show 5 more comments
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
You have to have two CDATA sections to concatenate the]]and the>- see this answer for the hows and the whys.
– Sean Vieira
Sep 26 '15 at 17:21
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
So this piece of C-like code could not easily be put in a CDATA section:if (a[b[c]]>10).
– Anders Tornblad
Mar 22 '17 at 9:43
29
29
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
How can a character of the CEND sequence be escaped?
– Thomas Weller
Sep 25 '15 at 8:17
19
19
You have to have two CDATA sections to concatenate the
]] and the > - see this answer for the hows and the whys.– Sean Vieira
Sep 26 '15 at 17:21
You have to have two CDATA sections to concatenate the
]] and the > - see this answer for the hows and the whys.– Sean Vieira
Sep 26 '15 at 17:21
1
1
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
does there have to be a new line character in between CDATA start and the raw data?
– Ben Sewards
Oct 20 '16 at 18:48
1
1
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
No there does not @BenSewards
– Sean Vieira
Oct 21 '16 at 2:32
4
4
So this piece of C-like code could not easily be put in a CDATA section:
if (a[b[c]]>10) .– Anders Tornblad
Mar 22 '17 at 9:43
So this piece of C-like code could not easily be put in a CDATA section:
if (a[b[c]]>10) .– Anders Tornblad
Mar 22 '17 at 9:43
|
show 5 more comments
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/
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
|
show 3 more comments
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/
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
|
show 3 more comments
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/
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/
edited Mar 25 '14 at 15:36
answered May 6 '10 at 20:35
Richard JP Le GuenRichard JP Le Guen
23.3k676111
23.3k676111
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
|
show 3 more comments
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
2
2
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
Then why "ý" is not allowed in CDATA?
– bjan
Jul 13 '13 at 5:19
9
9
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
@bjan - What makes you think that's an illegal character? Sounds like you might have an encoding problem.
– Richard JP Le Guen
Jul 13 '13 at 5:21
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
I opened the doc in IE, i am also using MSXML parser which declared it as an invalid character. I have an xsd in which it is declared as "type="xs:string"". Is it related with encoding or xml version?
– bjan
Jul 13 '13 at 5:42
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
CDATA is parsed and only valid range of characters are allowed here as well, it is used to escape blocks of text containing characters which would otherwise be recognized as markup
– bjan
Jul 13 '13 at 6:55
1
1
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
So we could use CDATA to smuggle some HTML into the XML document, so that the HTML doesn't confuse the XML document structure, and then use XSLT later to pull it out and spit it into a HTML document that is being output.
– Kaz
Oct 3 '13 at 6:10
|
show 3 more comments
One big use-case: your xml includes a program, as data (e.g. a web-page tutorial for Java). In that situation your data includes a big chunk of characters that include '&' and '<' but those characters aren't meant to be xml.
Compare:
<example-code>
while (x < len && !done)
print( "Still working, 'zzz'." );
++x;
</example-code>
with
<example-code><![CDATA[
while (x < len && !done)
print( "Still working, 'zzzz'." );
++x;
]]></example-code>
Especially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. As @paary mentioned, other common uses include when you're embedding URLs that contain ampersands. Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file.
(I suspect all the comparisons to comments are kinda misleading/unhelpful.)
add a comment |
One big use-case: your xml includes a program, as data (e.g. a web-page tutorial for Java). In that situation your data includes a big chunk of characters that include '&' and '<' but those characters aren't meant to be xml.
Compare:
<example-code>
while (x < len && !done)
print( "Still working, 'zzz'." );
++x;
</example-code>
with
<example-code><![CDATA[
while (x < len && !done)
print( "Still working, 'zzzz'." );
++x;
]]></example-code>
Especially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. As @paary mentioned, other common uses include when you're embedding URLs that contain ampersands. Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file.
(I suspect all the comparisons to comments are kinda misleading/unhelpful.)
add a comment |
One big use-case: your xml includes a program, as data (e.g. a web-page tutorial for Java). In that situation your data includes a big chunk of characters that include '&' and '<' but those characters aren't meant to be xml.
Compare:
<example-code>
while (x < len && !done)
print( "Still working, 'zzz'." );
++x;
</example-code>
with
<example-code><![CDATA[
while (x < len && !done)
print( "Still working, 'zzzz'." );
++x;
]]></example-code>
Especially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. As @paary mentioned, other common uses include when you're embedding URLs that contain ampersands. Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file.
(I suspect all the comparisons to comments are kinda misleading/unhelpful.)
One big use-case: your xml includes a program, as data (e.g. a web-page tutorial for Java). In that situation your data includes a big chunk of characters that include '&' and '<' but those characters aren't meant to be xml.
Compare:
<example-code>
while (x < len && !done)
print( "Still working, 'zzz'." );
++x;
</example-code>
with
<example-code><![CDATA[
while (x < len && !done)
print( "Still working, 'zzzz'." );
++x;
]]></example-code>
Especially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. As @paary mentioned, other common uses include when you're embedding URLs that contain ampersands. Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file.
(I suspect all the comparisons to comments are kinda misleading/unhelpful.)
edited May 28 '14 at 13:52
answered May 28 '14 at 13:26
not-just-yetinot-just-yeti
14.4k11313
14.4k11313
add a comment |
add a comment |
I once had to use CDATA when my xml element needed to store HTML code. Something like
<codearea>
<![CDATA[
<div> <p> my para </p> </div>
]]>
</codearea>
So CDATA means it will ignore any character which could otherwise be interpreted as XML tag like < and > etc.
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
add a comment |
I once had to use CDATA when my xml element needed to store HTML code. Something like
<codearea>
<![CDATA[
<div> <p> my para </p> </div>
]]>
</codearea>
So CDATA means it will ignore any character which could otherwise be interpreted as XML tag like < and > etc.
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
add a comment |
I once had to use CDATA when my xml element needed to store HTML code. Something like
<codearea>
<![CDATA[
<div> <p> my para </p> </div>
]]>
</codearea>
So CDATA means it will ignore any character which could otherwise be interpreted as XML tag like < and > etc.
I once had to use CDATA when my xml element needed to store HTML code. Something like
<codearea>
<![CDATA[
<div> <p> my para </p> </div>
]]>
</codearea>
So CDATA means it will ignore any character which could otherwise be interpreted as XML tag like < and > etc.
edited Jan 2 at 11:42
answered May 14 '15 at 4:28
OctaneOctane
9501011
9501011
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
add a comment |
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
2
2
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
Not "tag" but element in the first sentence.
– Ludovic Kuty
May 12 '16 at 11:21
add a comment |
The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
add a comment |
The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
add a comment |
The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
answered May 6 '10 at 20:23
fbreretofbrereto
29k16113168
29k16113168
add a comment |
add a comment |
From Wikipedia:
[In] an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup.
http://en.wikipedia.org/wiki/CDATA
Thus: text inside CDATA is seen by the parser but only as characters not as XML nodes.
add a comment |
From Wikipedia:
[In] an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup.
http://en.wikipedia.org/wiki/CDATA
Thus: text inside CDATA is seen by the parser but only as characters not as XML nodes.
add a comment |
From Wikipedia:
[In] an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup.
http://en.wikipedia.org/wiki/CDATA
Thus: text inside CDATA is seen by the parser but only as characters not as XML nodes.
From Wikipedia:
[In] an XML document or external parsed entity, a CDATA section is a
section of element content that is marked for the parser to interpret
as only character data, not markup.
http://en.wikipedia.org/wiki/CDATA
Thus: text inside CDATA is seen by the parser but only as characters not as XML nodes.
edited Apr 25 '18 at 10:53
Charlie Joynt
2,7521434
2,7521434
answered Jan 15 '15 at 14:49
ChdidChdid
17227
17227
add a comment |
add a comment |
As another example of its use:
If you have an RSS Feed (xml document) and want to include some basic HTML encoding in the display of the description, you can use CData to encode it:
<item>
<title>Title of Feed Item</title>
<link>/mylink/article1</link>
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</item>
The RSS Reader pulls in the description and renders the HTML within the CDATA.
Note - not all HTML tags work - I think it depends on the RSS reader you are using.
And as a explanation for why this example uses CData (and not the appropriate pubData and dc:creator tags): this is for website display using a RSS widget for which we have no real formatting control.
This enables us to specify the height and position of the included image, format the author names and date correctly, and so forth, without the need for a new widget. It also means I can script this and not have to add them by hand.
add a comment |
As another example of its use:
If you have an RSS Feed (xml document) and want to include some basic HTML encoding in the display of the description, you can use CData to encode it:
<item>
<title>Title of Feed Item</title>
<link>/mylink/article1</link>
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</item>
The RSS Reader pulls in the description and renders the HTML within the CDATA.
Note - not all HTML tags work - I think it depends on the RSS reader you are using.
And as a explanation for why this example uses CData (and not the appropriate pubData and dc:creator tags): this is for website display using a RSS widget for which we have no real formatting control.
This enables us to specify the height and position of the included image, format the author names and date correctly, and so forth, without the need for a new widget. It also means I can script this and not have to add them by hand.
add a comment |
As another example of its use:
If you have an RSS Feed (xml document) and want to include some basic HTML encoding in the display of the description, you can use CData to encode it:
<item>
<title>Title of Feed Item</title>
<link>/mylink/article1</link>
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</item>
The RSS Reader pulls in the description and renders the HTML within the CDATA.
Note - not all HTML tags work - I think it depends on the RSS reader you are using.
And as a explanation for why this example uses CData (and not the appropriate pubData and dc:creator tags): this is for website display using a RSS widget for which we have no real formatting control.
This enables us to specify the height and position of the included image, format the author names and date correctly, and so forth, without the need for a new widget. It also means I can script this and not have to add them by hand.
As another example of its use:
If you have an RSS Feed (xml document) and want to include some basic HTML encoding in the display of the description, you can use CData to encode it:
<item>
<title>Title of Feed Item</title>
<link>/mylink/article1</link>
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</item>
The RSS Reader pulls in the description and renders the HTML within the CDATA.
Note - not all HTML tags work - I think it depends on the RSS reader you are using.
And as a explanation for why this example uses CData (and not the appropriate pubData and dc:creator tags): this is for website display using a RSS widget for which we have no real formatting control.
This enables us to specify the height and position of the included image, format the author names and date correctly, and so forth, without the need for a new widget. It also means I can script this and not have to add them by hand.
edited Feb 23 at 4:49
Eureka
752312
752312
answered Sep 23 '14 at 15:44
LadyCygnusLadyCygnus
407613
407613
add a comment |
add a comment |
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed.
For example, if you want to pass a URL that contains & in it, you can use CDATA to do it. Otherwise, you will get an error as it will be parsed as regular XML.
add a comment |
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed.
For example, if you want to pass a URL that contains & in it, you can use CDATA to do it. Otherwise, you will get an error as it will be parsed as regular XML.
add a comment |
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed.
For example, if you want to pass a URL that contains & in it, you can use CDATA to do it. Otherwise, you will get an error as it will be parsed as regular XML.
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed.
For example, if you want to pass a URL that contains & in it, you can use CDATA to do it. Otherwise, you will get an error as it will be parsed as regular XML.
edited Jun 28 '13 at 20:39
Ry-♦
173k41351373
173k41351373
answered May 10 '12 at 4:52
paarypaary
353415
353415
add a comment |
add a comment |
It's used to contain data which could otherwise be seen as xml because it contains certain characters.
This way the data inside will be displayed, but not interpreted.
add a comment |
It's used to contain data which could otherwise be seen as xml because it contains certain characters.
This way the data inside will be displayed, but not interpreted.
add a comment |
It's used to contain data which could otherwise be seen as xml because it contains certain characters.
This way the data inside will be displayed, but not interpreted.
It's used to contain data which could otherwise be seen as xml because it contains certain characters.
This way the data inside will be displayed, but not interpreted.
edited Jul 12 '17 at 4:53
Emmett R.
1228
1228
answered May 6 '10 at 20:23
IkkeIkke
75.3k2282111
75.3k2282111
add a comment |
add a comment |
Usually used for embedding custom data, like pictures or sound data within an XML document.
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
add a comment |
Usually used for embedding custom data, like pictures or sound data within an XML document.
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
add a comment |
Usually used for embedding custom data, like pictures or sound data within an XML document.
Usually used for embedding custom data, like pictures or sound data within an XML document.
answered May 6 '10 at 20:26
JohanJohan
3,79512947
3,79512947
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
add a comment |
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
3
3
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
Although you could put text-encoded binary data in a CDATA section, you don't have to, because CDATA has nothing directly to do with binary anything.
– Joel Mueller
May 6 '10 at 22:32
add a comment |
The Cdata is a data which you may want to pass to an xml parser and still not interpreted as an xml.
Say for eg :- You have an xml which has encapsulates question/answer object . Such open fields can have any data which does not strictly fall under basic data type or xml defined custom data types. Like --Is this a correct tag for xml comment ? .--
You may have a requirement to pass it as it is without being interpreted by the xml parser as another child element. Here Cdata comes to your rescue . By declaring as Cdata you are telling the parser don't treat the data wrapped as an xml (though it may look like one )
add a comment |
The Cdata is a data which you may want to pass to an xml parser and still not interpreted as an xml.
Say for eg :- You have an xml which has encapsulates question/answer object . Such open fields can have any data which does not strictly fall under basic data type or xml defined custom data types. Like --Is this a correct tag for xml comment ? .--
You may have a requirement to pass it as it is without being interpreted by the xml parser as another child element. Here Cdata comes to your rescue . By declaring as Cdata you are telling the parser don't treat the data wrapped as an xml (though it may look like one )
add a comment |
The Cdata is a data which you may want to pass to an xml parser and still not interpreted as an xml.
Say for eg :- You have an xml which has encapsulates question/answer object . Such open fields can have any data which does not strictly fall under basic data type or xml defined custom data types. Like --Is this a correct tag for xml comment ? .--
You may have a requirement to pass it as it is without being interpreted by the xml parser as another child element. Here Cdata comes to your rescue . By declaring as Cdata you are telling the parser don't treat the data wrapped as an xml (though it may look like one )
The Cdata is a data which you may want to pass to an xml parser and still not interpreted as an xml.
Say for eg :- You have an xml which has encapsulates question/answer object . Such open fields can have any data which does not strictly fall under basic data type or xml defined custom data types. Like --Is this a correct tag for xml comment ? .--
You may have a requirement to pass it as it is without being interpreted by the xml parser as another child element. Here Cdata comes to your rescue . By declaring as Cdata you are telling the parser don't treat the data wrapped as an xml (though it may look like one )
answered Nov 19 '13 at 19:12
randomnessrandomness
941917
941917
add a comment |
add a comment |
It escapes a string that cannot be passed to XML as usual:
Example:
The string contains "&" in it.
You can not:
<FL val="Company Name">Dolce & Gabbana</FL>
Therefore, you must use CDATA:
<FL val="Company Name"> <![CDATA["Dolce & Gabbana"]]> </FL>
add a comment |
It escapes a string that cannot be passed to XML as usual:
Example:
The string contains "&" in it.
You can not:
<FL val="Company Name">Dolce & Gabbana</FL>
Therefore, you must use CDATA:
<FL val="Company Name"> <![CDATA["Dolce & Gabbana"]]> </FL>
add a comment |
It escapes a string that cannot be passed to XML as usual:
Example:
The string contains "&" in it.
You can not:
<FL val="Company Name">Dolce & Gabbana</FL>
Therefore, you must use CDATA:
<FL val="Company Name"> <![CDATA["Dolce & Gabbana"]]> </FL>
It escapes a string that cannot be passed to XML as usual:
Example:
The string contains "&" in it.
You can not:
<FL val="Company Name">Dolce & Gabbana</FL>
Therefore, you must use CDATA:
<FL val="Company Name"> <![CDATA["Dolce & Gabbana"]]> </FL>
answered Mar 25 at 3:28
HoangYellHoangYell
34737
34737
add a comment |
add a comment |
protected by Aniket Thakur Aug 4 '15 at 12:16
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?