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

StackOverflow https://stackoverflow.com/questions/20966700

  •  25-09-2022
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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]]>

نصائح أخرى

The term CDATA comes from the SGML world, which is the complex predecessor of XML. The term is short for Character Data and means that the data contains of characters, and should not be parsed. Tags, entities, attributes, processing instructions inside CDATA are treated as text, not as XML elements.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top