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

前端 未结 13 2252
独厮守ぢ
独厮守ぢ 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:22

    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:

    
      Title of Feed Item
      /mylink/article1
      
        
          
          Author Names
          
    Date
    Paragraph of text describing the article to be displayed

    ]]>

    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.

提交回复
热议问题