Try it

CDATA

Sortyra team · · 3 min read

CDATA is a special section in an XML file whose content is read as plain text, not as tags. It is mainly useful for product descriptions containing HTML or the & character, which would otherwise break the feed. The section starts with "<![CDATA[" and ends with "]]>".

What is CDATA

In XML, some characters have a special meaning. The < character starts a tag and the & character starts a shorthand for a special character. If a product description contains "Tent & tarp" or an HTML tag <p>, the program thinks it is XML markup and won't read the file.

There are two solutions:

  1. Write each such character as a replacement – & as &amp;, < as &lt;.
  2. Wrap the whole text in a CDATA block (from character data).

CDATA works like an envelope marked "do not open, just pass on". The program doesn't analyse the content and takes it as it is. For the channel, both methods are equivalent – the result is the same text.

What it looks like in a feed

<!-- Heureka, Zboží: a description with HTML in a CDATA block -->
<DESCRIPTION><![CDATA[<p>Tent for 2 people, tarp & groundsheet included.</p>]]></DESCRIPTION>

<!-- Google Merchant: the same text with & replaced -->
<g:description>Tent for 2 people, tarp &amp; groundsheet included.</g:description>

The first line passes on the text, HTML tag included, unchanged; the second writes & as a replacement and needs no CDATA.

What it is used for

  • Product descriptions with HTML – paragraphs, lists and bold text from the online shop.
  • Titles and brands containing &, for example "B&S" or "Mix & Match".
  • Texts with angle brackets and links with parameters in an element's text.

CDATA is part of the XML standard, so comparison sites and Google can read it.

What to watch out for

  • ]]> must not appear inside. This string ends the CDATA, and the rest of the text breaks the feed.
  • It doesn't work in attributes. In an attribute you must always use replacements such as &amp;.
  • It doesn't solve encoding. CDATA won't fix broken accented characters or forbidden control characters – that is what correct UTF-8 encoding is for.
  • HTML stays HTML. CDATA only passes the tags on; a channel that doesn't support HTML in descriptions will show them as text or remove them. Check the channel's specification.
  • Blocks cannot be nested one inside another.

How Sortyra helps

When loading a supplier's feed, Sortyra takes CDATA content unchanged and corrects a lone & outside CDATA to &amp; so the reading doesn't stop. In outputs it writes special characters as replacements, so the resulting feed is valid XML even without CDATA.

Frequently asked questions

Do I have to put the product description in CDATA?

No. It is enough for the &, < and > characters to be written as replacements. CDATA is just a more convenient way for long texts with HTML.

Why does the feed stop at the & character?

In XML, the & character starts a shorthand for a special character. A lone & is a markup error, and the program rejects the whole file because of it.

Does Heureka accept CDATA?

Yes, CDATA is a standard part of XML and comparison sites read it routinely.

Try it on your own feed