What is it for! [CDATA []] in XML?

9

In some examples of platforms, you have tags% , but what's the use of this in XML?

Model of an XML to be followed by a platform.

<?xml version="1.0" encoding="UTF-8"?>
<loja>
   <produto>
      <link><![CDATA[http://www.loja.com.br/blusas/blusa-feminina?idparceiro=P1]]></link>
      <imagem><![CDATA[http://www.loja.com.br/imagens/blusa-feminina-1.jpg]]></imagem>
      <nome><![CDATA[Blusa feminina vermelha]]></nome>
      <categoria><![CDATA[Blusas Femininas]]></categoria>
      <descricao><![CDATA[Blusa feminina com gola em V e detalhes em strass.]]></descricao>
      <valor><![CDATA[119,00]]></valor>
      <valor_promo><![CDATA[95,90]]></valor_promo>
      <parcelamento><![CDATA[2x R$47,95]]></parcelamento>
      <cor><![CDATA[Vermelho, Azul, Branco]]></cor>
      <marca><![CDATA[Tommy Hilfiger]]></marca>
      <modelo><![CDATA[Único]]></modelo>
      <material><![CDATA[100% algodão]]></material>
      <tamanho><![CDATA[P, M, G]]></tamanho>
      <sexo><![CDATA[Feminino]]></sexo>
   </produto>
</loja>
    
asked by anonymous 20.08.2015 / 03:36

1 answer

11

The CDATA serves to indicate that the text within its area is a text and can not be interpreted as part of XML markup.

This is useful when a portion of the text of a given element can be confused with portions of the XML markup, which is not the case for the example shown. It's a way of escaping the characters.

You should have a platform-specific reason to use indiscriminately. Maybe because of their failure to specify them. Maybe because they have no control over the content and there may be conflicting characters (may contain HTML). Maybe for some reason only they can explain (probably via documentation). What is certain is that it should be followed if they do.

An example of good use would be:

<secao><![CDATA[<sexo>Feminino</sexo>]]><secao>

What seems to be an tag of XML is just a common text that happens to look like and probably represents another XML.

Wikipedia .

    
20.08.2015 / 03:46