Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does <![CDATA[<![CDATA[some text]]]]><![CDATA[>]]> in XML mean? [duplicate]

Tags:

xml

cdata

I am new to XML and its related technologies.

This CDATA tag always comes at the beginning, and then followed by some stuff

I have use this in my XML file:

<text><![CDATA[<![CDATA[TAX INVOICE]]]]><![CDATA[>]]></text>

I have following question. Please help me.

what does <![CDATA[some text]]]]> means?

like image 771
Girish K Avatar asked Sep 15 '25 01:09

Girish K


1 Answers

Unless there are special characters such as "&" and "<" in the content, the string

<![CDATA[xxxxx]]>

means exactly the same as

xxxxx

The difference is that in the second form, "&" and "<" have a special meaning, while in the CDATA form, the only thing with a special meaning is the string "]]>" which acts as a terminator.

Your more complex example:

<![CDATA[<![CDATA[TAX INVOICE]]]]><![CDATA[>]]>

is a bit of a nightmare, and results from a sloppy programming habit of wrapping text in CDATA sections out of laziness. CDATA sections cannot be nested, so the first ]]> terminates the first <!CDATA[, which means that the string is equivalent to

<![CDATA[TAX INVOICE]]>

You might think that this in turn is equivalent to

TAX INVOICE

but that is not the case, because an XML parser will only interpret the outer CDATA delimiters, and the content it will pass to the application is therefore

<![CDATA[TAX INVOICE]]>
like image 76
Michael Kay Avatar answered Sep 17 '25 17:09

Michael Kay