What is it about CDATA Sections?

Volume 6, Issue 75; 24 Aug 2003

A short, cheeky complaint about the sad state of XML books.

Any fool can crticize, condemn, and complain—and most fools do.

Dale Carnegie

This essay is a little bit cheeky on my part. Authors work hard, I know from personal experience, and maybe it's unfair to judge a book by a single section, to paraphrase a common saying. We all make mistakes, right? I'll try to ameliorate my criticism by not mentioning any names. But I have to ask, what is so hard to understand about CDATA sections?

Wandering through the book store yesterday, I paused to skim the XML books. A few of years ago, just before the bubble burst, when the XML books were coming out fast and furious, I happened to notice an error in one of them. Something to do with CDATA sections, but I've forgotten exactly what, so now when I pick up a random XML book, I always look to see how CDATA sections are described.

The first book I skim says that CDATA sections begin with “ <![cdata[ ”. Bzzzt. Wrong, but thank you for playing.

The next book I pick up says that CDATA sections cannot contain “]]”. Sigh. Nope.

The third book gets it right.

The fourth book correctly points out that CDATA sections cannot contain “ ]]> ”, but fails to mention that the string “ ]]> ” (unescaped) can't ever occur in a document except when it ends a CDATA section. Close, but no cigar.

The last book I picked up didn't mention CDATA sections at all. No points off, I suppose. If I promised to teach you XML in four and a third minutes or something like that, maybe I wouldn't try to explain CDATA sections either.

I wonder if XML 2.0 should even contain CDATA sections?


Sad that a book author can get this kind of thing wrong. I never remember this kind of thing. but that is what google and http://www.w3.org/TR/2000/REC-xml-20001006#sec-cdata-sect is for. If an author can&apos;t be bothered to look up this kind of thing to "GET IT RIGHT" why should I pay for his book. I am not interested in paying for guesses. I need answers.

—Posted by Nick Chalko on 25 Aug 2003 @ 07:51 UTC #

I can gladly confirm that my copy of Goldfarb&apos;s and Prescod&apos;s _XML Handbook_ correctly discusses CDATA sections. Unfortunately, another XML book that I own doesn&apos;t. Funny that I never picked up that error tho. Thanks for the head&apos;s up.

—Posted by James Cerra on 06 Sep 2003 @ 01:58 UTC #

What i&apos;d like from XML 2.0 is a BDATA section so we can embed jpegs directly in XML :-o

—Posted by Paul Downey on 08 Oct 2003 @ 08:33 UTC #