What does <![CDATA[]]> in XML mean?

前端 未结 13 2216
独厮守ぢ
独厮守ぢ 2020-11-21 07:52

I often find this strange CDATA tag in XML files:


I have observed that this CD

13条回答
  •  自闭症患者
    2020-11-21 08:09

    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:

    
    while (x < len && !done) {
        print( "Still working, 'zzz'." );
        ++x;
        }
    
    

    with

    
    

    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.)

提交回复
热议问题