Why is the XML tag data inside this <! [CDATA []]>

I have seen that many XML files have data inside this <![CDATA[ ]]>. What is the use of this?

+3
source share
4 answers

From Wikipedia

The CDATA section begins with the following sequence:

<![CDATA[

and ends with the first occurrence of the sequence:

]]>

All characters enclosed between these two sequences are interpreted as characters, not markup or entity references. For example, in a line like this:

<sender>John Smith</sender>

opening and closing sender tags are interpreted as markup. However, if it is written like this:

<![CDATA[<sender>John Smith</sender>]]>

then the code is interpreted in the same way as if it were written as follows:

&lt;sender&gt;John Smith&lt;/sender&gt;

See the Wiki for more details .

+5

CDATA :

XML CDATA , , , .

, , <![CDATA[ ]]>.

, HTML XML. :

<root>
    <myhtml>
        <div><b>Foo bar</b></div>
    </myhtml>
</root>

<div><b>Foo bar</b></div> DOM. , , DTD.

:

<root>
    <myhtml>
        <![CDATA[ <div><b>Foo bar</b></div> ]]>
    </myhtml>
</root>

<div><b>Foo bar</b></div> node.

+3

, " " xml. "" xml-, .

0

, CDATA .

For example, the image you want to send javascript inside an XML document, since it most likely contains special characters (<,>, &, etc.), the xml parser will generate errors.

With this tag, the parser will not parse it and will not produce any errors.

0
source

Source: https://habr.com/ru/post/1780007/


All Articles